Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Nov 2003
    Location
    Code Heaven
    Posts
    129
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Detecting the key teh user pressed...

    Ok...so the event.keyCode property returns the Unicode of the key pressed,also this property has a value only when the user presses a button otherwise it'll be undefined.
    To return the pressed key I(and most I guess...) use:
    function getKey()
    {
    return(String.fromCharCode(event.keyCode));
    }

    Now,the problem is I can't detect the backspace and arrow(cursor) keys....but yet some sites look like doing this....so how is it done then??

  • #2
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You must use onkeyup as opposed to onkeypress to cature some event.keys. This link may help.

    .....Willy

  • #3
    Regular Coder
    Join Date
    Nov 2003
    Location
    Code Heaven
    Posts
    129
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I knew that some event props were useful only for some specific event handlers.
    Thx!

  • #4
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    You may have to use onkeydown as this may give a different result to onkeypress

    See here for more info

    http://www.huntingground.freeserve.c...ts/keycode.htm


  •  

    Posting Permissions

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