www.webdeveloper.com
Results 1 to 4 of 4

Thread: Detect keypress in window

  1. #1
    Join Date
    Jan 2008
    Location
    ncl,uk
    Posts
    56

    Question Detect keypress in window

    Is there any way to detect a key being pressed in the window? I have tried the following but it doesnt work:
    document.onkeyup = KeyCheck;
    function KeyCheck()
    {
    var keyID = event.keyCode;
    alert(keyID )
    }

  2. #2
    Join Date
    Apr 2010
    Posts
    25
    I know this is silly but could you need a semi colon after alert(...);
    If you look in the bottom right of the browser you might see an error.

  3. #3
    Join Date
    Feb 2006
    Posts
    2,927
    // You may need a doctype (or use document.body) for ie.
    // For non-ie you need the argument that is passed in non ie event handlers
    Code:
    document.onkeyup= function(e){
        e= window.event || e;
        alert(e.keyCode);
    }

  4. #4
    Join Date
    Jan 2008
    Location
    ncl,uk
    Posts
    56

    resolved

    Thanks mrhoo that does exactly what i need

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles