


Example analysis of keyboard event usage in javascript_javascript skills
This article analyzes the usage of keyboard events in JavaScript with examples. Share it with everyone for your reference. The details are as follows:
Keyboard events include onkeydown, onkeypress and onkeyup
Event initialization
function keyDown(){} document.onkeydown = keyDown; //论按下键盘上的哪个键,都将调用KeyDown()函数。
DOM standard
function keyDown(e) { var keycode = e.which; //取得对应的键值(数字) var realkey = String.fromCharCode(e.which); //取得代表改键的真正字符 alert("按键码: " + keycode + " 字符: " + realkey); } document.onkeydown = keyDown
Under IE
function keyDown() { var keycode = event.keyCode; //IE下取得键值的方法 var realkey = String.fromCharCode(event.keyCode); alert("按键码: " + keycode + " 字符: " + realkey); } document.onkeydown = keyDown
Compatible methods
function keyUp(e) { var currKey=0,e=e||event; currKey=e.keyCode||e.which||e.charCode; var keyName = String.fromCharCode(currKey); alert("按键码: " + currKey + " 字符: " + keyName); } document.onkeyup = keyUp;
Principle of use: keydown event is most useful for function keys, while keypress event is most useful for printable keys
The following key code values are only fully valid in the text box. If used in the
Key code value (keyCode) of alphabetic and numeric keys
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 48
1 49
2 50
3 51
4 52
5 53
6 54
7 55
8 56
9 57
Key code value (keyCode) of the key on the numeric keyboard Function key key code value (keyCode)
Key code
0 96
1 97
2 98
3 99
4 100
5 101
6 102
7 103
8 104
9 105
* 106
107
Enter 108
- 109
. 110
/ 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
Control key key code value (keyCode)
Key code
BackSpace 8
Esc 27
Right Arrow 39
Left Arrow 37
Down Arrow 40
Up Arrow 38
-_ 189
.> 190
Spacebar 32
Tab 9
Clear 12
Page Up 33
Page Down 34
Enter 13
Insert 45
;: 186
Delete 46
`~ 192
/? 191
Num Lock 144
Control 17
Home 36
End 35
Shift 16
[{ 219
}] 221
| 220
= 187
,< 188
'" 222
Cape Lock 20
Alt 18
I hope this article will be helpful to everyone’s JavaScript programming design.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



According to news from this website on February 29, Maicong today launched two versions of "Hyacinth Switch" and "Glazed Ice Cream Switch" for the K87 three-mode mechanical keyboard. The keyboard features "Gasket structure, 80% arrangement", related shaft keyboards The price information is as follows: "Hyacinth Switch" version: initial price is 299 yuan. "Liuguang Ice Cream Switch" version: initial price is 379 yuan. According to reports, the series of keyboards use Gasket structure, 87-key 80% arrangement, full-key rollover, and support thermal For plugging and unplugging, it claims to use "original/MDA two-color PBT keycaps", uses a 1.2mm single-key slotted PCB (lower lamp position), is equipped with RGB lighting effects, and has a magnetic absorption nameplate design. In addition, this keyboard is equipped with a 6000 mAh battery and a wireless delay of 3ms. The official size and size of the keyboard have not been announced.

According to news from this site on August 12, VGN launched the co-branded "Elden Ring" keyboard and mouse series on August 6, including keyboards, mice and mouse pads, designed with a customized theme of Lani/Faded One. The current series of products It has been put on JD.com, priced from 99 yuan. The co-branded new product information attached to this site is as follows: VGN丨Elden Law Ring S99PRO Keyboard This keyboard uses a pure aluminum alloy shell, supplemented by a five-layer silencer structure, uses a GASKET leaf spring structure, has a single-key slotted PCB, and the original height PBT material Keycaps, aluminum alloy personalized backplane; supports three-mode connection and SMARTSPEEDX low-latency technology; connected to VHUB, it can manage multiple devices in one stop, starting at 549 yuan. VGN丨Elden French Ring F1PROMAX wireless mouse the mouse

Apple mobile keyboard users want to set up the handwriting input method, but don’t know how to do it. It’s actually very simple. Users can directly select the handwriting input method in the phone’s keyboard settings. If not, they can also manually add a handwriting input method. How to set the handwriting input method on the Apple mobile phone keyboard A: Enable the handwriting input method directly in the keyboard settings 1. When Apple users use the input method, the handwriting input method is enabled by default. 2. Users only need to click and hold the lower left corner to select the handwriting input method while typing. 3. If the user does not have a handwriting input method in his mobile phone, he can also add it manually. 4. The user enters the settings, finds the universal keyboard settings, and adds the handwriting input option to the first keyboard. 5. Use handwriting input method to

How to set the skin for WeChat keyboard? WeChat Keyboard is a very smart mobile phone input method software. This software has many user-friendly functions. It allows users to choose their own input mode and find the expressions they want as quickly as possible on this software. send out. This software also allows users to change the skin of the keyboard themselves. Many users are not sure how to change the skin. The editor below has compiled the skin changing methods for your reference. How to set the WeChat keyboard skin In WeChat, SMS or other applications that require the use of the keyboard on your phone, you can click the input method settings icon in the upper left corner of the keyboard to enter the settings page to view the function setting options for various input methods. 2. Click "Personalized Skin" on the settings page of the input method.

According to news from this site on March 7, Keychron today released the Q10Max three-mode mechanical keyboard. The keyboard adopts 75% Alice configuration. The shaft-less keycap kit is priced at 1,238 yuan. The keyboard equipped with Jiadalong’s customized Jupiter shaft and PBT keycaps is priced at 1,358 yuan. It will go on sale at Tmall flagship store at 8 o’clock tonight. The Q10Max mechanical keyboard belongs to the Keychron QMax three-mode "Aluminum Tuo Tuo" series, which has a number of keyboards with different layouts such as Q1/Q2/Q3/Q5/Q6/Q60/Q65Max on the market. ▲ Keychron Q10Max keyboard product features The Q10Max body is made of 6063 aluminum CNC process, using 75% Alice configuration, and the official claims that it “fits the human wrist”

According to news from this website on March 31, Aitou recently launched an 87-key magnetic axis keyboard model "NA87MAG" on JD.com. The standard price is 219 yuan. If you pay a 10 yuan deposit, you will get an immediate discount of 20 yuan on the final payment. The actual price is 199 yuan. According to reports, this keyboard uses an Asat structure and is claimed to provide "HIFI-level typing sound quality and a consistent tough feel." Users can also adjust the feel of the keyboard by replacing different pads to achieve customization from tough to soft. Switching requirements. In addition, this keyboard is also equipped with a "three-dimensional game inner structure", which is said to be able to concentrate the sound of each key through a single-key closed design in a chessboard format, thereby "achieving three-dimensional sound optimization"; it also has 16.8 million colors of RGB light. Additionally, this keyboard features Le

According to news from this website on July 19, Lingbao K87/PRO three-mode mechanical keyboard will be on sale at 8 o'clock tonight. The main differences between the two versions are the shaft/color/battery differences. The standard version is equipped with 4000 mAh. Battery, the PRO version is equipped with an 8000 mAh battery. The price information compiled by this website is as follows: K87 Light Cloud White: 99 yuan K87 Night Purple/Xiaguang Purple/Sunny Mountain Blue: 149 yuan K87 Dust Gray/Star Daisy Purple: 199 yuan K87PRO : 249 yuan According to reports, this keyboard adopts a Gasket structure, uses an 80% arrangement layout, is available in a variety of colors, has built-in lower light RGB lights, and supports three-mode connection 2.4G (1KHz)/wired (1KHz)/Bluetooth (125Hz) ). In terms of specifications, series keyboards are optional

You can set the typing sound in the WeChat keyboard, so where can you adjust the typing sound? Users need to open the WeChat keyboard, click More Settings, and turn on the key sounds inside. This introduction to typing sound setting method will tell you the specific operation method. The following is a detailed introduction, take a look! Where to adjust the typing sound on WeChat keyboard: Turn on the key sound in the keyboard settings. Specific method: 1. First click the icon in the keyboard. 2. Then click More Settings. 3. Find the key sound inside and open it.
