Catching keyboard events using Javascript

A cross-browser script to catch key­board events in Javascript with some links for fur­ther research if you are interested.

It is pos­si­ble to catch key presses in a browser using Javascript. Click below for a cross-browser script to catch key­board events. Click­ing in the first text area and press any keys on your key­board (as if to enter text). The sec­ond textarea serves as a real-time log and shows you info about what key you pressed.

For a sim­pler exam­ple, also see http://www.faqts.com/knowledge_base/view.phtml/aid/11802

  • Ron Fiber

    Nice! I like the redesign. Btw, there is a good tuto­r­ial about jscript keys over at http://tech.irt.org/articles/js195/

    Keep up the good work

  • may­worth

    I can­not get this code to work in phoenix 0.5? does it work for you, are there some require­ments that I need to meet before I can run this script inside HTML page?

  • / snip­tools

    May­worth,

    Yes this code does work in Phoenix 0.5 which was the last pre-Firebird ver­sion. It works in all mozilla vari­ants at least on *nix and win­dows sys­tems. Haven't tested on macs — which OS are you on?

  • srini­vas

    Hi

    we are try­ing to do with hotkeys.…could you please help us how it works .

    if we press with "shift+a" it should pop up with the help.

    I really appre­ci­ate if you can help in this regard

    Thanks
    srini­vas sanka

  • / snip­tools

    Srini­vas, look at the code sam­ple. It is easy to cap­ture whether SHIFT key is pressed (TRUE or FALSE in my code) and then equate the return value from the key­Press event to "A". If both are true, then the user has pressed SHIFT A, and you can trig­ger your Help win­dow or lead the user to your Help page (through URL.location).