javascript – keyCode for each key and usage with demo

keyCode

keyCode or which

JavaScript key events provide properties called ‘keyCode’ and ‘which’ , which you can use to identify which key in keyboard has been pressed by the user. This can be useful in scenarios where you want to perform some action at client side when user interacts through keyboard.

event.keyCode
Returns the Unicode value of a non-character key in a keypress event or any key in any other type of keyboard event.

‘A’ Through ‘Z’
Key Code
 A  65
 B 66
C 67
D 68
E 69
F 70
G 71
H 72
I 73
J 74
K 75
L 76
M 77
N 78
O 79
P 80
Q 81
R 82
S 83
T 84
U 85
V 86
W 87
X 88
Y 89
Z 90
‘0’ Through ‘9’
Key Code
 0 48
 1 49
 2 50
 3 51
 4 52
 5 53
 6 54
 7 55
 8 56
 9 57
Function Keys
Key Code
 F1  112
 F2  113
 F3  114
 F4  115
 F5  116
 F6  117
 F7  118
 F8  119
 F9  120
 F10  121
 F11  122
 F12  123
Keys on the Numeric Keypad
Key Code
 0 ( numpad )  96
 1 ( numpad ) 97
 2 ( numpad ) 98
 3 ( numpad ) 99
 4 ( numpad ) 100
 5 ( numpad ) 101
 6 ( numpad ) 102
 7 ( numpad ) 103
 8 ( numpad ) 104
 9 ( numpad ) 105
 MULTIPLICATION SIGN (*) key 106
 PLUS SIGN (+) key 107
 MINUS SIGN (-) key 109
 DECIMAL POINT(.) key 110
 DIVISION SIGN (/) key 111
Other Keys
Key Code
 SEMI COLON (;)  186
 EQUAL SIGN (=)  187
 COMMA (,) 188
 HYPHEN (‐) 189
 PERIOD (.) 190
 FORWARD SLASH (/) 191
 BACK SLASH (\) 220
 GRAVE ACCENT (`)  192
 OPEN BRACKET ([) 219
 CLOSE BRACKET (]) 221
 SINGLE QUOTE (‘) 222
Other Keys
Key Code
 BACKSPACE  8
 TAB  9
 ENTER  13
 SHIFT 16
 CTRL 17
 ALT 18
 PAUSE 19
 CAPS LOCK 20
 ESC  27
 SPACEBAR 32
 PAGE UP 33
 PAGE DOWN 34
 END 35
 HOME 36
 LEFT ARROW 37
 UP ARROW 38
 RIGHT ARROW 39
 DOWN ARROW 40
 PRINT SCREEN  42
 INS  45
 DEL 46
 LEFT WINDOWS KEY 91
 RIGHT WINDOWS KEY 92
 SELECT KEY 93
 NUM LOCK 144
SCROLL LOCK 145

keyCode Example

click here see the full Example.

Other useful properties :

event.altKey – ALT key               event.ctrlKey – CTRL key               event.shiftKey – SHIFT key

References :

https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent.keyCode

https://developer.mozilla.org/en-US/docs/Web/API/event.keyCode

Author of CodeForEach.com . Loves coding and related technologies.
 

www.000webhost.com