javascript keypress codes code example
Example 1: keypress javascript
The keypress event has been deprecated,
you should look to use beforeinput : https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/beforeinput_event
or keydown : https://developer.mozilla.org/en-US/docs/Web/API/Document/keydown_event
instead.
(And don't forget to like answers that help you !)
Example 2: js keycodes
backspace 8
tab 9
enter 13
shift 16
ctrl 17
alt 18
pause/break 19
caps lock 20
escape 27
page up 33
Space 32
page down 34
end 35
home 36
arrow left 37
arrow up 38
arrow right 39
arrow down 40
print screen 44
insert 45
delete 46
0 48
1 49
2 50
3 51
4 52
5 53
6 54
7 55
8 56
9 57
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
left window key 91
right window key 92
select key 93
numpad 0 96
numpad 1 97
numpad 2 98
numpad 3 99
numpad 4 100
numpad 5 101
numpad 6 102
numpad 7 103
numpad 8 104
numpad 9 105
multiply 106
add 107
subtract 109
decimal point 110
divide 111
f1 112
f2 113
f3 114
f4 115
f5 116
f6 117
f7 118
f8 119
f9 120
f10 121
f11 122
f12 123
num lock 144
scroll lock 145
My Computer (multimedia keyboard) 182
My Calculator (multimedia keyboard) 183
semi-colon 186
equal sign 187
comma 188
dash 189
period 190
forward slash 191
open bracket 219
back slash 220
close braket 221
single quote 222
Example 3: jquery event keycode
$('#someTextBox').keypress(function(event){
var keycode = (event.keyCode ? event.keyCode : event.which);
if(keycode == '13'){
alert('You pressed a "enter" key in textbox');
}
});
Example 4: keycode
Easily check JavaScript KeyboardEvent properties (e.key, e.code, e.which,
e.keyCode… and more) with Key.js:
https://keyjs.dev
Key Code | Key Description
----------------------------
0 | Unidentified key
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | Backspace
9 | Tab
10 |
11 |
12 | Clear
13 | Enter
14 |
15 |
16 | Shift
17 | Control
18 | Alt
19 | Pause/Break
20 | Caps Lock
21 |
22 |
23 |
24 |
25 |
26 |
27 | Escape
28 |
29 |
30 |
31 |
32 | Space Bar
33 | Page Up
34 | Page Down
35 | End
36 | Home
37 | Left Arrow
38 | Up Arrow
39 | Right Arrow
40 | Down Arrow
41 | Select
42 | Print
43 | Execute
44 | Print Screen / Snapshot
45 | Insert
46 | Delete
47 | Help
48 | 0
49 | 1
50 | 2
51 | 3
52 | 4
53 | 5
54 | 6
55 | 7
56 | 8
57 | 9
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 | A
66 | B
67 | C
68 | D
69 | E
70 | F
71 | G
72 | H
73 | I
74 | J
75 | K
76 | L
77 | M
78 | N
79 | O
80 | P
81 | Q
82 | R
83 | S
84 | T
85 | U
86 | V
87 | W
88 | X
89 | Y
90 | Z
91 | Left Window/Meta/OS Key
92 | Right Window/Meta/OS Key
93 | Context Menu
94 |
95 |
96 | Numpad 0
97 | Numpad 1
98 | Numpad 2
99 | Numpad 3
100 | Numpad 4
101 | Numpad 5
102 | Numpad 6
103 | Numpad 7
104 | Numpad 8
105 | Numpad 9
106 | Multiply
107 | Add
108 | Keypad Enter
109 | Subtract
110 | Decimal Point
111 | Divide
112 | F1
113 | F2
114 | F3
115 | F4
116 | F5
117 | F6
118 | F7
119 | F8
120 | F9
121 | F10
122 | F11
123 | F12
124 | F13
125 | F14
126 | F15
127 | F16
128 | F17
129 | F18
130 | F19
131 | F20
132 | F21
133 | F22
134 | F23
135 | F24
136 | F25
137 | F26
138 | F27
139 | F28
140 | F29
141 | F30
142 | F31
143 | F32
144 | Num Lock
145 | Scroll Lock
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 | Navigate/Page Back
167 | Navigate/Page Forward
168 | Reload/Refresh Page
169 |
170 |
171 |
172 |
173 |
174 | Audio Volume Down
175 | Audio Volume Up
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 | Semi-colon
187 | Equal Sign
188 | Comma
189 | Dash
190 | Period
191 | Forward Slash
192 | Grave Accent
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 | Open Bracket
220 | Back Slash
221 | Close Bracket
222 | Single Quote
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
231 |
232 |
233 |
234 |
235 |
236 |
237 |
238 |
239 |
240 |
241 |
242 |
243 |
244 |
245 |
246 |
247 |
248 |
249 |
250 |
251 |
252 |
253 |
254 |
255 |
Example 5: key code list
pygame
Constant ASCII Description
---------------------------------
K_BACKSPACE \b backspace
K_TAB \t tab
K_CLEAR clear
K_RETURN \r return
K_PAUSE pause
K_ESCAPE ^[ escape
K_SPACE space
K_EXCLAIM ! exclaim
K_QUOTEDBL " quotedbl
K_HASH # hash
K_DOLLAR $ dollar
K_AMPERSAND & ampersand
K_QUOTE quote
K_LEFTPAREN ( left parenthesis
K_RIGHTPAREN ) right parenthesis
K_ASTERISK * asterisk
K_PLUS + plus sign
K_COMMA , comma
K_MINUS - minus sign
K_PERIOD . period
K_SLASH / forward slash
K_0 0 0
K_1 1 1
K_2 2 2
K_3 3 3
K_4 4 4
K_5 5 5
K_6 6 6
K_7 7 7
K_8 8 8
K_9 9 9
K_COLON : colon
K_SEMICOLON ; semicolon
K_LESS < less-than sign
K_EQUALS = equals sign
K_GREATER > greater-than sign
K_QUESTION ? question mark
K_AT @ at
K_LEFTBRACKET [ left bracket
K_BACKSLASH \ backslash
K_RIGHTBRACKET ] right bracket
K_CARET ^ caret
K_UNDERSCORE _ underscore
K_BACKQUOTE ` grave
K_a a a
K_b b b
K_c c c
K_d d d
K_e e e
K_f f f
K_g g g
K_h h h
K_i i i
K_j j j
K_k k k
K_l l l
K_m m m
K_n n n
K_o o o
K_p p p
K_q q q
K_r r r
K_s s s
K_t t t
K_u u u
K_v v v
K_w w w
K_x x x
K_y y y
K_z z z
K_DELETE delete
K_KP0 keypad 0
K_KP1 keypad 1
K_KP2 keypad 2
K_KP3 keypad 3
K_KP4 keypad 4
K_KP5 keypad 5
K_KP6 keypad 6
K_KP7 keypad 7
K_KP8 keypad 8
K_KP9 keypad 9
K_KP_PERIOD . keypad period
K_KP_DIVIDE / keypad divide
K_KP_MULTIPLY * keypad multiply
K_KP_MINUS - keypad minus
K_KP_PLUS + keypad plus
K_KP_ENTER \r keypad enter
K_KP_EQUALS = keypad equals
K_UP up arrow
K_DOWN down arrow
K_RIGHT right arrow
K_LEFT left arrow
K_INSERT insert
K_HOME home
K_END end
K_PAGEUP page up
K_PAGEDOWN page down
K_F1 F1
K_F2 F2
K_F3 F3
K_F4 F4
K_F5 F5
K_F6 F6
K_F7 F7
K_F8 F8
K_F9 F9
K_F10 F10
K_F11 F11
K_F12 F12
K_F13 F13
K_F14 F14
K_F15 F15
K_NUMLOCK numlock
K_CAPSLOCK capslock
K_SCROLLOCK scrollock
K_RSHIFT right shift
K_LSHIFT left shift
K_RCTRL right control
K_LCTRL left control
K_RALT right alt
K_LALT left alt
K_RMETA right meta
K_LMETA left meta
K_LSUPER left Windows key
K_RSUPER right Windows key
K_MODE mode shift
K_HELP help
K_PRINT print screen
K_SYSREQ sysrq
K_BREAK break
K_MENU menu
K_POWER power
K_EURO Euro