Which key?

See also Key Move

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.

String.fromCharCode(event.keyCode)

Pressing key "a" returns "a"

Where x = ISO-Latin-1 codeset value, returns the associated letter or symbol.

String.fromCharCode(97) returns "a"

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.

MethodLetter or SymbolISO-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

CharacteronkeypressonkeydownDescription
---00 - 07 --- ---
--- --- 08Backspace
---0909Horizontal tab
---10 --- Line feed
---11 - 12 --- ---
---1313Return
---14 - 15 --- ---
--- --- 16Shift
--- --- 17CTRL
--- --- 18ALT
--- --- 19Pause
--- --- 20Caps Lock
--- 21 - 26 --- ---
---2727Escape
---28 - 31 --- ---
---3232Space
!33 --- Exclamation mark
--- --- 33Page Up
"34 --- Quotation mark
#35 --- Number sign
$36 --- Dollar sign
--- --- 36Home
%37 --- Percent sign
--- --- 37Arrow Left
&38 --- Ampersand
--- --- 38Arrow Up
'39 --- Apostrophe
--- --- 39Arrow Right
(40 --- Left parenthesis
--- --- 40Arrow Down
)41 --- Right parenthesis
*42 --- Asterisk
+43 --- Plus sign
,44 --- Comma
-45 --- Hyphen
--- --- 45Insert
.46 --- Period (fullstop)
/47 --- Forward slash
04848Digit 0
14949Digit 1
25050Digit 2
35151Digit 3
45252Digit 4
55353Digit 5
65454Digit 6
75555Digit 7
85656Digit 8
95757Digit 9
:58 --- Colon
;59 --- Semicolon
<60 --- Less than
=61 --- Equals sign
>62 --- Greater than
?63 --- Question mark
@64 --- Commercial at
A6565Capital A
B6666Capital B
C6767Capital C
D6868Capital D
E6969Capital E
F7070Capital F
G7171Capital G
H7272Capital H
I7373Capital I
J7474Capital J
K7575Capital K
L7676Capital L
M7777Capital M
N7878Capital N
O7979Capital O
P8080Capital P
Q8181Capital Q
R8282Capital R
S8383Capital S
T8484Capital T
U8585Capital U
V8686Capital V
W8787Capital W
X8888Capital X
Y8989Capital Y
Z9090Capital Z
[91 --- Left square bracket
--- --- 91Left Win Key
\92 --- Backslash
--- --- 92Right Win Key
]93 --- Right square bracket
--- --- 93Menu
^94 --- Caret
_95 --- Underscore
`96 --- Acute accent
--- --- 96Keypad 0
a97 --- Small a
--- --- 97Keypad 1
b98 --- Small b
--- --- 98Keypad 2
c99 --- Small c
--- --- 99Keypad 3
d100 --- Small d
--- --- 100Keypad 4
e101 ---Small e
--- --- 101Keypad 5
f102 --- Small f
--- --- 102Keypad 6
g103 --- Small g
--- --- 103Keypad 7
h104 --- Small h
--- --- 104Keypad 8
i105 --- Small i
--- --- 105Keypad 9
j106 --- Small j
--- --- 106Keypad *
k107 --- Small k
--- --- 107Keypad +
l108 --- Small l
m109 --- Small m
--- --- 109Keypad -
n110 --- Small n
--- --- 110Keypad .
o111 --- Small o
--- --- 111Keypad /
p112 --- Small p
--- --- 112F1
q113 --- Small q
--- --- 113F2
r114 --- Small r
--- --- 114F3
s115 --- Small s
--- --- 115F4
t116 --- Small t
--- --- 116F5
u117 --- Small u
--- --- 117F6
v118 --- Small v
--- --- 118F7
w119 --- Small w
--- --- 119F8
x120 --- Small x
--- --- 120F9
y121 --- Small y
--- --- 121F10
z122 --- Small z
--- --- 122F11
{123 --- Left brace
--- --- 123F12
|124 --- Vertical bar
}125 --- Right brace
~126 --- Tilde
--- --- 144Num Lock
--- --- 145Scroll Lock
; --- 186Semi Colon
= --- 187Equal
, --- 188Comma
- --- 189Dash
. --- 190Dot
/ --- 191Forward Slash
' --- 192Apostrophe
[ --- 219Left Square Bracket
] --- 221Right Square Bracket
# --- 222Hash
` --- 223Acute accent

For more ISO Latin-1 Character Set see Characters