JavaScript Hotkey Function
This JavaScript function allows hotkeys to be used on web pages. A hotkey may be any standard printing character in combination with either the control key, the alt key, or the meta key, although care should be taken not to conflict with browser shortcut keys.
Note that because of the different keyboard layouts in use, and because of the way that JavaScript handles keyboard events, it is best to limit your range of hotkeys to the following characters:
0 to 9 A to Z a to z - . ,
The action taken when a hotkey is pressed may be either to link to another page, or to invoke some JavaScript code - normally an existing function, or it could, for example, be an instruction to activate a form button, or check a radio button. Note that whether hotkeys take precedence over access keys or vice versa depends on the browser.
Hotkeys are particularly useful for facilitating accessibility when major functions are normally provided through the mouse.
These routines have been tested with Internet Explorer, Mozilla, and Opera. Note that unlike with the accesskey attribute, IE does not require the enter key to be depressed.
In the following examples:
The <body> tag requires an onkeypress attribute as follows:
<body onkeypress="hotKeys(event);">
The function includes a data array which associates the hotkey with the required action. The data array in the example of this web page is as follows:
keyActions [0] = {character: "2",
actionType: "link",
param: "../error404.html"};
keyActions [1] = {character: "L",
actionType: "code",
param: "openPopup('images/image.jpg','The Fouda Blanc Sangle');"};
Download Zip File (1.86 Kb).