PDA

View Full Version : how to capture a keyboard key


imroue
11-06-2002, 02:25 AM
Does anyone know what the command in javascript is to find out what key on the keyboard a user has pressed. Even if you have the syntax for a couple of keys.. that would be very helpful.
Thanks:)

Slurry
11-06-2002, 03:59 AM
window.event.keyCode

thatll return what key the user has pressed

lpok
11-06-2002, 05:21 AM
Netscape and IE do this differently. Check out these links:

For Netscape (http://www.javascriptkit.com/javatutors/javascriptkey.shtml)
For IE (http://www.javascriptkit.com/javatutors/javascriptkey6.shtml)

imroue
11-14-2002, 03:02 PM
Originally posted by lpok
Netscape and IE do this differently. Check out these links:

For Netscape (http://www.javascriptkit.com/javatutors/javascriptkey.shtml)
For IE (http://www.javascriptkit.com/javatutors/javascriptkey6.shtml)

Thanks,
These work to recognize all the keys on the keyboard except the arrow keys. Is it possible to find that?

lpok
11-14-2002, 05:55 PM
I think only the newer versions of IE lets you bind the arrow keys. That's because those keys are reserved for the browser for scrolling. That's why I don't use them much, so I can't think of how to do it off my head right now. Maybe someone here knows.

whammy
11-15-2002, 12:32 AM
I'm curious as to what you are trying to accomplish with this technique. There are many valid uses for capturing key codes, but a lot of the time I see people trying to change the way forms work by default, which only ends up annoying users. :)

jkd
11-15-2002, 12:49 AM
Originally posted by lpok
I think only the newer versions of IE lets you bind the arrow keys. That's because those keys are reserved for the browser for scrolling. That's why I don't use them much, so I can't think of how to do it off my head right now. Maybe someone here knows.

In IE, arrow keys don't fire a keypress event, only onkeydown and onkeyup