SniptoolsSniptools | Design & Technology Observations

RSS

Catching keyboard events using Javascript

May 27th 2003
5 Comments

Respond
Trackback

A cross-browser script to catch keyboard events in Javascript with some links for further research if you are interested.

It is possible to catch key presses in a browser using Javascript. Click below for a cross-browser script to catch keyboard events. Clicking in the first text area and press any keys on your keyboard (as if to enter text). The second textarea serves as a real-time log and shows you info about what key you pressed.

For a simpler example, also see http://www.faqts.com/knowledge_base/view.phtml/aid/11802




This post is tagged

5 Comments

  1. Ron Fiber

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

    Keep up the good work

  2. mayworth

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

  3. Shashank

    Mayworth,

    Yes this code does work in Phoenix 0.5 which was the last pre-Firebird version. It works in all mozilla variants at least on *nix and windows systems. Haven’t tested on macs — which OS are you on?

  4. srinivas

    Hi

    we are trying 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 appreciate if you can help in this regard

    Thanks
    srinivas sanka

  5. Shashank Tripathi

    Srinivas, look at the code sample. It is easy to capture whether SHIFT key is pressed (TRUE or FALSE in my code) and then equate the return value from the keyPress event to “A”. If both are true, then the user has pressed SHIFT A, and you can trigger your Help window or lead the user to your Help page (through URL.location).

Incoming Links