views:

468

answers:

2

I have a question regarding the onkeypress event on Javascript.

Is it possible to detect Just Ctl key or Alt Key? At the moment if both Ctl and m are pressed the onkeypress event can trigger a click. Is it possible to do just Ctl key by itself?

Looking forward to your comments

A: 

From the looks of it, no, you can't just capture the Ctrl key. The hotkeys jQuery plugin which focuses exclusively on capturing keys doesn't capture the straight "Ctrl" key either, so I'm guessing it's not possible. You can catch it with the mouse events, but that's not quite the same thing.

http://jshotkeys.googlepages.com/test-static-01.html

altCognito
+3  A: 

onkeypress just catches character keys. Use onkeydown and/or onkeyup for the other keys. See Peter-Paul Koch on key events.

Gumbo