Wednesday, March 3, 2010

ASP.NET Shortcut Keys

Technology
ASP.Net & Javascript
Introduction
There are several reasons why you may want to capture the key press event in a browser window. Looking for something like that means that you work as a professional. We will see how you can achive that in internet explorer.
Key codes
In the beginning we will see a list of most used keys with related IE key codes:
  • Alphabetic keys (A~Z): ASCII code of uppercase version of the letter 65 to 90
  • Space : 32
  • Enter : 13
  • Tab : 9
  • ESC : 27
  • Backspace : 8
  • Shit : 16
  • Control : 17
  • Alt : 18
  • Caps : 20
  • Num : 144
  • 0 ~ 9 : 48 ~ 57
  • Left : 37
  • Up : 38
  • Right : 39
  • Down : 40
  • F1 ~ F12 : 112 ~ 123 (I want here to tell you a note about F1)

Implementation
// javascript code
document.onkeyup = KeyCheck;
function KeyCheck(){var KeyID = event.keyCode;switch(KeyID){ .... }

Notes

If you want to catch a function Keys F1 ~ F10

IE events will still be applied for that F key for example F5 will refresh the page.

in this case you have to add the following lines to prevent passing the event to IE :

event.keyCode = 0;

event.returnValue = false;

in case of F1 :

if(document.onhelp == null)

document.onhelp = function() { return false; }

The above is only works for IE

Comments and Questions are welcomed

3 comments:

  1. nice Post
    you should try it with firefox as well
    because a lot of people prefer using it

    and please remove the word Verification it is annoying

    ReplyDelete
  2. Thanks Starbon for both comment and advice

    ReplyDelete