问题
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
回答1:
onkeypress
just catches character keys. Use onkeydown
and/or onkeyup
for the other keys. See Peter-Paul Koch on key events.
回答2:
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
来源:https://stackoverflow.com/questions/929729/javascript-onkeypress