JS monitor keyboard press event JavaScript JQuery

Monitor keyboard press

$(document).keypress(function (e) {
    
    
	// 回车和空格按下事件
   if (e.keyCode == 13 || e.keyCode == 32) {
    
    
        $("#play").click();
    }
})

Monitor window changes

window.onresize = function(){
    
    
 // 你要干的事情
 alert("123");
}

keyCode encyclopedia attached

The key code value of the letter and number keys (keyCode)

button Key code button Key code button Key code button Key code
A 65 J 74 S 83 1 49
B 66 K 75 T 84 2 50
C 67 L 76 U 85 3 51
D 68 M 77 V 86 4 52
E 69 N 78 W 87 5 53
F 70 THE 79 X 88 6 54
G 71 P 80 Y 89 7 55
H 72 Q 81 WITH 90 8 56
I 73 R 82 0 48 9 57

The key code value of the key on the numeric keypad (keyCode)

button Key code button Key code
0 96 8 104
1 97 9 105
2 98 * 106
3 99 + 107
4 100 Enter 108
5 101 - 109
6 102 . 110
7 103 / 111

Function key key code value (keyCode)

button Key code button Key code
F1 112 F7 118
F2 113 F8 119
F3 114 F9 120
F4 115 F10 121
F5 116 F11 122
F6 117 F12 123

Control key key code value (keyCode)

button Key code button Key code button Key code button Key code
BackSpace 8 Esc 27 Right Arrow 39 -_ 189
Tab 9 Spacebar 32 Dw Arrow 40 .> 190
Clear 12 Page Up 33 Insert 45 /? 191
Enter 13 Page Down 34 Delete 46 `~ 192
Shift 16 End 35 Num Lock 144 [{ 219
Control 17 Home 36 ;: 186 | 220
Alt 18 Left Arrow 37 =+ 187 ]} 221
Cape Lock 20 Up Arrow 38 ,< 188 '" 222

Multimedia key code value (keyCode)

button Key code
Volume up 175
Volume down 174
stop 179
Mute 173
Browser 172
mail 180
search for 170
Favorites 171

End to spread flowers

Author: yufire © [email protected]

Guess you like

Origin blog.csdn.net/weixin_43420255/article/details/106017811