This paper illustrates the method of acquiring and judging the keyboard keys by JS. Share to everyone for your reference, specific as follows:
JS inside the keyboard event is often used, so the keyboard event to collect the corresponding key code to share under:
KeyCode 8 = BackSpace BackSpace keycode 9 = tab Tab keycode = Clear KeyCode = Enter KeyCode = shift_l keycode 17 = control_l KeyCode = alt_l KeyCode = Pause KeyCode = Caps_lock keycode = Escape escape keycode = Space Ke
Ycode = Prior KeyCode = Next keycode/End keycode = Home KeyCode Panax Notoginseng = left keycode/up keycode/Right KeyCode = down KeyCode = Select KeyCode = Print KeyCode = Execute keycode = Insert keycode MB = Delete key Code = Help keycode = 0 equal braceright keycode-1 exclam onesuperior keycode = 2 Quotedbl twosuperior Keyco De Wuyi = 3 section threesuperior keycode 4 dollar keycode 5 percent keycode = 6 ampersand keycode-7 slash Braceleft keycode = 8 Parenleft bracketleft keycode = 9 parenright bracketright keycode (a) keycode = b b k Eycode = c c KeyCode (d) keycode = e e eurosign keycode (f f keycode) = g g keycode A/h keycode 73 = I i KeyCode-J-J KeYcode = k K keycode = l l keycode (M m mu keycode) = n n keycode l = o keycode (p) keycode KeyCode = r r keycode m = s S keycode = t T keycode--u u keycode-V v. KeyCode v-W keycode Ycode (y y keycode) = Z Z keycode = kp_0 kp_0 keycode (kp_1 kp_1) = KeyCode kp_2
3 KeyCode = Kp_4 kp_4 keycode [kp_5 kp_5 keycode 102 = kp_6 kp_6 keycode] kp_7 kp_7 (keycode) = Kp_8 kp_8 KeyCode = Kp_9 kp_9 keycode [kp_multiply kp_multiply keycode] = Kp_add kp_add keycode 108 = kp_separator KP_Se Parator keycode 109 = kp_subtract kp_subtract keycode) = Kp_decimal kp_decimal keycode = kp_divide KP_Divide keyCod E 112 = F1 KeyCode 113 = F2 KeyCode 114 = F3 KeyCode + = F4 keycode 116 = F5 KeyCode 117 = F6 KeyCode 118 = F7 KeyCode 1 = F8 KeyCode = F9 keycode 121 = F10 KeyCode = 122 F11-keycode = 123 F12 KeyCode = 124 F13 = KeyCode F14 126 = F15 KeyCode 127 = KeyCode 128 = F17 KeyCode 129 = F18 keycode 130 = F19 KeyCode 131 = F20 KeyCode 132 = F21 KeyCode F16 = F22 keycode 1 F23 keycode 135 = F24 KeyCode 136 = num_lock KeyCode 137 = scroll_lock KeyCode 187 = Acute grave keycode 188 = comma Semicolon KeyCode 189 = minus underscore keycode-190 = period colon keycode = numbersign apostrophe keycode 210 = Plus Minus hyphen Macron KeyCode 211 = keycode 212 = Copyright Registered keycode 213 = guillemotleft Guillemotright keyCode 21 4 = masculine Ordfeminine keycode 215 = AE AE keycode 216 = cent yen keycode 217 = Questiondown exclamdown KeyCode 218 = O Nequarter onehalf threequarters keycode-less Greater bar keycode 221 = plus asterisk Asciitilde keycode = Multip ly division
keyCode 228 = acircumflex Acircumflex
keyCode 229 = ecircumflex Ecircumflex
keyCode 230 = icircumflex Icircumf Lex keycode 231 = Ocircumflex Ocircumflex keycode 232 = Ucircumflex Ucircumflex keycode 233 = Ntilde Ntilde KeyCode 234 = Yacute Yacute KeyCode 235 = Oslash ooblique keycode 236 = aring aring keycode 237 = Ccedilla Ccedilla keycode 238 = Thorn Thorn keycode 239 = ETH ETH keycode = diaeresis cedilla currency keycode 241 = Agrave agrave Atilde atilde keycode = 242 Egrave egrave 243 = igrave Igrave
keyCode 244 = ograve Ograve otilde Otilde
keyCode 245 = ugrave Ugrave
keyCode 246 = adiaeresis Adiaer ESIs keycode 247 = ediaeresis ediaeresis keycode 248 = idiaeresis idiaeresis keycode 249 = odiaeresis Odiaeresis KeyCode 2 Udiaeresis udiaeresis KeyCode 251 = ssharp question backslash keycode-252 = asciicircum degree KeyCode 253 = 3 Sterli
ng KeyCode 254 = Mode_switch
Use the KeyCode property of the event object to determine the key value entered
eg
Copy Code code as follows:
if (event.keycode==13) alert ("enter!");
Key value corresponding table
A 0x65 U 0x85
B 0x66 V 0x86
C 0x67 W 0X87
D 0x68 X 0x88
E 0x69 Y 0x89
F 0x70 Z 0x90
G 0x71 0 0x48
H 0x72 1 0x49
I 0x73 2 0X50
J 0x74 3 0x51
K 0x75 4 0x52
l 0x76 5 0x53
M 0x77 6 0x54
N 0x78 7 0x55
O 0x79 8 0x56
P 0X80 9 0x57
Q 0X Bayi ESC 0x1b
R 0x82 CTRL 0x11
S 0x83 SHIFT 0X10
T 0x84 ENTER 0XD
If you want to use a combination of keys, you can determine whether the keys are pressed at the same time, such as CTRL, SHIFT, and the combination of the ALT key to determine whether to press the CTRL key, the SHIFT key, and the ALT key.
JS Get keyboard events:
<script type= "Text/javascript" Language=javascript charset= "UTF-8" >
document.onkeydown=function (Event) {
var e = Event | | window.event | | arguments.callee.caller.arguments[0];
if (e && e.keycode==27) {//press ESC
//What to do
}
if (e && e.keycode==113) {//press F2
//What to do
}
if (e && e.keycode==13) {//Enter key
//What to do
}
};
</script>
As long as you define the actions of these keys, you will be able to respond to these keys in your browser, compatible with all browsers currently in the browser.
JS to judge keyboard keys
Window.document.onkeydown = Disablerefresh;
function Disablerefresh (evt) {
evt = (evt)? evt:window.event
if (evt.keycode) {
if (Evt.keycode = 116) { C21/>//do Something
}}}
The key code is shown in the previous example.
Use the KeyCode property of the event object to determine the key value entered
eg
if (event.keycode==13) {
var iekey=event.keycode;//gets the key value, the numeric form of
var realkey=string.fromcharcode (Iekey)// Converts the numeric form of a key value into a true key
alert (Realkey);
}
The corresponding table of key values is shown in the previous example
I hope this article will help you with JavaScript programming.