The following information will allow "Hot Keys" to be created to run functions
event.keyCode returns the ISO-Latin-1 codeset value of the key pressed.
Pressing key "a" returns "97"
String.fromCharCode(x) returns the letter or symbol associated with the ISO-Latin-1 codeset value.
Where x = event.keyCode, the letter or symbol returned will be according to which key is pressed.
Pressing key "a" returns "a"
Where x = ISO-Latin-1 codeset value, returns the associated letter or symbol.
The following script will determine which key was pressed on your keyboard.
This could be used to run a function, script, or load another page etc. when a particular key is press.
| Method | Letter or Symbol | ISO-Latin-1 codeset value |
| onkeypress | ||
| onkeydown |
Note:
Depending on the key pressed onkeydown may return a different value to onkeypress.
The script below uses the onkeypress method
<script type="text/javascript">
<!--
function getKey(e) {
keycode=(!e?event.keyCode:e.which)
keyChar=String.fromCharCode(keycode)
document.getElementById("display1").innerHTML=keyChar
document.getElementById("display2").innerHTML=keycode
}
document.onkeypress = getKey
// -->
</script>
<table border=1>
<tr align="center"><td>Method</td><td>Letter or Symbol</td><td>ISO-Latin-1 codeset value</td></tr>
<tr align="center">
<td><b>onkeypress</b></td>
<td><div id= display1 style="font-weight:bold"> </div></td>
<td><div id= display2> </div></td>
</tr>
</table>
Using e.keycode with onkeypress in Firefox always returns a value of zero
var key = (!e? event.keyCode:e.keyCode)
The following table shows the character and/or number returned for onkeypress and onkeydpown
| Character | onkeypress | onkeydown | Description |
| --- | 00 - 07 | --- | --- |
| --- | --- | 08 | Backspace |
| --- | 09 | 09 | Horizontal tab |
| --- | 10 | --- | Line feed |
| --- | 11 - 12 | --- | --- |
| --- | 13 | 13 | Return |
| --- | 14 - 15 | --- | --- |
| --- | --- | 16 | Shift |
| --- | --- | 17 | CTRL |
| --- | --- | 18 | ALT |
| --- | --- | 19 | Pause |
| --- | --- | 20 | Caps Lock |
| --- | 21 - 26 | --- | --- |
| --- | 27 | 27 | Escape |
| --- | 28 - 31 | --- | --- |
| --- | 32 | 32 | Space |
| ! | 33 | --- | Exclamation mark |
| --- | --- | 33 | Page Up |
| " | 34 | --- | Quotation mark |
| # | 35 | --- | Number sign |
| $ | 36 | --- | Dollar sign |
| --- | --- | 36 | Home |
| % | 37 | --- | Percent sign |
| --- | --- | 37 | Arrow Left |
| & | 38 | --- | Ampersand |
| --- | --- | 38 | Arrow Up |
| ' | 39 | --- | Apostrophe |
| --- | --- | 39 | Arrow Right |
| ( | 40 | --- | Left parenthesis |
| --- | --- | 40 | Arrow Down |
| ) | 41 | --- | Right parenthesis |
| * | 42 | --- | Asterisk |
| + | 43 | --- | Plus sign |
| , | 44 | --- | Comma |
| - | 45 | --- | Hyphen |
| --- | --- | 45 | Insert |
| . | 46 | --- | Period (fullstop) |
| / | 47 | --- | Forward slash |
| 0 | 48 | 48 | Digit 0 |
| 1 | 49 | 49 | Digit 1 |
| 2 | 50 | 50 | Digit 2 |
| 3 | 51 | 51 | Digit 3 |
| 4 | 52 | 52 | Digit 4 |
| 5 | 53 | 53 | Digit 5 |
| 6 | 54 | 54 | Digit 6 |
| 7 | 55 | 55 | Digit 7 |
| 8 | 56 | 56 | Digit 8 |
| 9 | 57 | 57 | Digit 9 |
| : | 58 | --- | Colon |
| ; | 59 | --- | Semicolon |
| < | 60 | --- | Less than |
| = | 61 | --- | Equals sign |
| > | 62 | --- | Greater than |
| ? | 63 | --- | Question mark |
| @ | 64 | --- | Commercial at |
| A | 65 | 65 | Capital A |
| B | 66 | 66 | Capital B |
| C | 67 | 67 | Capital C |
| D | 68 | 68 | Capital D |
| E | 69 | 69 | Capital E |
| F | 70 | 70 | Capital F |
| G | 71 | 71 | Capital G |
| H | 72 | 72 | Capital H |
| I | 73 | 73 | Capital I |
| J | 74 | 74 | Capital J |
| K | 75 | 75 | Capital K |
| L | 76 | 76 | Capital L |
| M | 77 | 77 | Capital M |
| N | 78 | 78 | Capital N |
| O | 79 | 79 | Capital O |
| P | 80 | 80 | Capital P |
| Q | 81 | 81 | Capital Q |
| R | 82 | 82 | Capital R |
| S | 83 | 83 | Capital S |
| T | 84 | 84 | Capital T |
| U | 85 | 85 | Capital U |
| V | 86 | 86 | Capital V |
| W | 87 | 87 | Capital W |
| X | 88 | 88 | Capital X |
| Y | 89 | 89 | Capital Y |
| Z | 90 | 90 | Capital Z |
| [ | 91 | --- | Left square bracket |
| --- | --- | 91 | Left Win Key |
| \ | 92 | --- | Backslash |
| --- | --- | 92 | Right Win Key |
| ] | 93 | --- | Right square bracket |
| --- | --- | 93 | Menu |
| ^ | 94 | --- | Caret |
| _ | 95 | --- | Underscore |
| ` | 96 | --- | Acute accent |
| --- | --- | 96 | Keypad 0 |
| a | 97 | --- | Small a |
| --- | --- | 97 | Keypad 1 |
| b | 98 | --- | Small b |
| --- | --- | 98 | Keypad 2 |
| c | 99 | --- | Small c |
| --- | --- | 99 | Keypad 3 |
| d | 100 | --- | Small d |
| --- | --- | 100 | Keypad 4 |
| e | 101 | --- | Small e |
| --- | --- | 101 | Keypad 5 |
| f | 102 | --- | Small f |
| --- | --- | 102 | Keypad 6 |
| g | 103 | --- | Small g |
| --- | --- | 103 | Keypad 7 |
| h | 104 | --- | Small h |
| --- | --- | 104 | Keypad 8 |
| i | 105 | --- | Small i |
| --- | --- | 105 | Keypad 9 |
| j | 106 | --- | Small j |
| --- | --- | 106 | Keypad * |
| k | 107 | --- | Small k |
| --- | --- | 107 | Keypad + |
| l | 108 | --- | Small l |
| m | 109 | --- | Small m |
| --- | --- | 109 | Keypad - |
| n | 110 | --- | Small n |
| --- | --- | 110 | Keypad . |
| o | 111 | --- | Small o |
| --- | --- | 111 | Keypad / |
| p | 112 | --- | Small p |
| --- | --- | 112 | F1 |
| q | 113 | --- | Small q |
| --- | --- | 113 | F2 |
| r | 114 | --- | Small r |
| --- | --- | 114 | F3 |
| s | 115 | --- | Small s |
| --- | --- | 115 | F4 |
| t | 116 | --- | Small t |
| --- | --- | 116 | F5 |
| u | 117 | --- | Small u |
| --- | --- | 117 | F6 |
| v | 118 | --- | Small v |
| --- | --- | 118 | F7 |
| w | 119 | --- | Small w |
| --- | --- | 119 | F8 |
| x | 120 | --- | Small x |
| --- | --- | 120 | F9 |
| y | 121 | --- | Small y |
| --- | --- | 121 | F10 |
| z | 122 | --- | Small z |
| --- | --- | 122 | F11 |
| { | 123 | --- | Left brace |
| --- | --- | 123 | F12 |
| | | 124 | --- | Vertical bar |
| } | 125 | --- | Right brace |
| ~ | 126 | --- | Tilde |
| --- | --- | 144 | Num Lock |
| --- | --- | 145 | Scroll Lock |
| ; | --- | 186 | Semi Colon |
| = | --- | 187 | Equal |
| , | --- | 188 | Comma |
| - | --- | 189 | Dash |
| . | --- | 190 | Dot |
| / | --- | 191 | Forward Slash |
| ' | --- | 192 | Apostrophe |
| [ | --- | 219 | Left Square Bracket |
| ] | --- | 221 | Right Square Bracket |
| # | --- | 222 | Hash |
| ` | --- | 223 | Acute accent |
For more ISO Latin-1 Character Set see Characters