Tuesday, March 27, 2007

How to add keyboard shortcuts to your website

By Justin Silverton

The following javascript code will allow you to add keyboard shortcuts to any webpage.

The code

(put this on any page where you want keyboard shortcuts)

I can't put the HTML code please refer:- Html Code

(put this in a file called shortcut.js and upload to the same directory as the webpage with the above code). This example will display an alert message when the escape key is pressed.

function keyShortcut() {
var e = window.event;
var code = e.keyCode;
if (code == 112) { //checks for the escape key
alert('escape key pressed');
}
}

The following are some more keyboard codes that can be used within the above script (in the if code == X, where X is one of the codes below).

key Code
tab 9
enter 13
leftwindow key 91
right window key 92
f1 112
f2 113
f3 114
f4 115
f5 116
f6 117
f7 118
f8 119
f9 120
f10 121
f11 122
f12 123