Javascript onkeypress

青春壹個敷衍的年華 提交于 2019-12-18 09:45:13

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!