Home Web Front-end JS Tutorial How to get keyboard content in js

How to get keyboard content in js

Sep 08, 2017 am 11:22 AM
javascript content keyboard

 1<script type="text/javascript" language=JavaScript charset="UTF-8">
 2       document.onkeydown=function(event){
 3             var e = event || window.event || arguments.callee.caller.arguments[0];
 4             if(e && e.keyCode==27){ // 按 Esc 
 5                 //要做的事情
 6               }
 7             if(e && e.keyCode==113){ // 按 F2 
 8                  //要做的事情
 9                }            
10              if(e && e.keyCode==13){ // enter 键
11                  //要做的事情
12             }
13         }; 
14 </script>
15 只要你定义了这些键的动作,你在浏览器里按下这些键就会响应,兼容目前所有浏览器。
Copy after login
  1 js 里面的键盘事件经常用到,所以收集了键盘事件对应的键码来分享下:
  2 keyCode 8 = BackSpace BackSpace
  3 keyCode 9 = Tab Tab
  4 keyCode 12 = Clear
  5 keyCode 13 = Enter
  6 keyCode 16 = Shift_L
  7 keyCode 17 = Control_L
  8 keyCode 18 = Alt_L
  9 keyCode 19 = Pause
 10 keyCode 20 = Caps_Lock
 11 keyCode 27 = Escape Escape
 12 keyCode 32 = space
 13 keyCode 33 = Prior
 14 keyCode 34 = Next
 15 keyCode 35 = End
 16 keyCode 36 = Home
 17 keyCode 37 = Left
 18 keyCode 38 = Up
 19 keyCode 39 = Right
 20 keyCode 40 = Down
 21 keyCode 41 = Select
 22 keyCode 42 = Print
 23 keyCode 43 = Execute
 24 keyCode 45 = Insert
 25 keyCode 46 = Delete
 26 keyCode 47 = Help
 27 keyCode 48 = 0 equal braceright
 28 keyCode 49 = 1 exclam onesuperior
 29 keyCode 50 = 2 quotedbl twosuperior
 30 keyCode 51 = 3 section threesuperior
 31 keyCode 52 = 4 dollar
 32 keyCode 53 = 5 percent
 33 keyCode 54 = 6 ampersand
 34 keyCode 55 = 7 slash braceleft
 35 keyCode 56 = 8 parenleft bracketleft
 36 keyCode 57 = 9 parenright bracketright
 37 keyCode 65 = a A
 38 keyCode 66 = b B
 39 keyCode 67 = c C
 40 keyCode 68 = d D
 41 keyCode 69 = e E EuroSign
 42 keyCode 70 = f F
 43 keyCode 71 = g G
 44 keyCode 72 = h H
 45 keyCode 73 = i I
 46 keyCode 74 = j J
 47 keyCode 75 = k K
 48 keyCode 76 = l L
 49 keyCode 77 = m M mu
 50 keyCode 78 = n N
 51 keyCode 79 = o O
 52 keyCode 80 = p P
 53 keyCode 81 = q Q at
 54 keyCode 82 = r R
 55 keyCode 83 = s S
 56 keyCode 84 = t T
 57 keyCode 85 = u U
 58 keyCode 86 = v V
 59 keyCode 87 = w W
 60 keyCode 88 = x X
 61 keyCode 89 = y Y
 62 keyCode 90 = z Z
 63 keyCode 96 = KP_0 KP_0
 64 keyCode 97 = KP_1 KP_1
 65 keyCode 98 = KP_2 KP_2
 66 keyCode 99 = KP_3 KP_3
 67 keyCode 100 = KP_4 KP_4
 68 keyCode 101 = KP_5 KP_5
 69 keyCode 102 = KP_6 KP_6
 70 keyCode 103 = KP_7 KP_7
 71 keyCode 104 = KP_8 KP_8
 72 keyCode 105 = KP_9 KP_9
 73 keyCode 106 = KP_Multiply KP_Multiply
 74 keyCode 107 = KP_Add KP_Add
 75 keyCode 108 = KP_Separator KP_Separator
 76 keyCode 109 = KP_Subtract KP_Subtract
 77 keyCode 110 = KP_Decimal KP_Decimal
 78 keyCode 111 = KP_pide KP_pide
 79 keyCode 112 = F1
 80 keyCode 113 = F2
 81 keyCode 114 = F3
 82 keyCode 115 = F4
 83 keyCode 116 = F5
 84 keyCode 117 = F6
 85 keyCode 118 = F7
 86 keyCode 119 = F8
 87 keyCode 120 = F9
 88 keyCode 121 = F10
 89 keyCode 122 = F11
 90 keyCode 123 = F12
 91 keyCode 124 = F13
 92 keyCode 125 = F14
 93 keyCode 126 = F15
 94 keyCode 127 = F16
 95 keyCode 128 = F17
 96 keyCode 129 = F18
 97 keyCode 130 = F19
 98 keyCode 131 = F20
 99 keyCode 132 = F21
100 keyCode 133 = F22
101 keyCode 134 = F23
102 keyCode 135 = F24
103 keyCode 136 = Num_Lock
104 keyCode 137 = Scroll_Lock
105 keyCode 187 = acute grave
106 keyCode 188 = comma semicolon
107 keyCode 189 = minus underscore
108 keyCode 190 = period colon
109 keyCode 192 = numbersign apostrophe
110 keyCode 210 = plusminus hyphen macron
111 keyCode 211 =
112 keyCode 212 = copyright registered
113 keyCode 213 = guillemotleft guillemotright
114 keyCode 214 = masculine ordfeminine
115 keyCode 215 = ae AE
116 keyCode 216 = cent yen
117 keyCode 217 = questiondown exclamdown
118 keyCode 218 = onequarter onehalf threequarters
119 keyCode 220 = less greater bar
120 keyCode 221 = plus asterisk asciitilde
121 keyCode 227 = multiply pision
122 keyCode 228 = acircumflex Acircumflex
123 keyCode 229 = ecircumflex Ecircumflex
124 keyCode 230 = icircumflex Icircumflex
125 keyCode 231 = ocircumflex Ocircumflex
126 keyCode 232 = ucircumflex Ucircumflex
127 keyCode 233 = ntilde Ntilde
128 keyCode 234 = yacute Yacute
129 keyCode 235 = oslash Ooblique
130 keyCode 236 = aring Aring
131 keyCode 237 = ccedilla Ccedilla
132 keyCode 238 = thorn THORN
133 keyCode 239 = eth ETH
134 keyCode 240 = diaeresis cedilla currency
135 keyCode 241 = agrave Agrave atilde Atilde
136 keyCode 242 = egrave Egrave
137 keyCode 243 = igrave Igrave
138 keyCode 244 = ograve Ograve otilde Otilde
139 keyCode 245 = ugrave Ugrave
140 keyCode 246 = adiaeresis Adiaeresis
141 keyCode 247 = ediaeresis Ediaeresis
142 keyCode 248 = idiaeresis Idiaeresis
143 keyCode 249 = odiaeresis Odiaeresis
144 keyCode 250 = udiaeresis Udiaeresis
145 keyCode 251 = ssharp question backslash
146 keyCode 252 = asciicircum degree
147 keyCode 253 = 3 sterling
148 keyCode 254 = Mode_switch
149 使用event对象的keyCode属性判断输入的键值
150 eg:if(event.keyCode==13)alert(“enter!”);
151 键值对应表
152 A  0X65  U   0X85
153 B  0X66  V   0X86
154 C  0X67  W   0X87
155 D  0X68  X   0X88
156 E  0X69  Y   0X89
157 F  0X70  Z   0X90
158 G  0X71  0   0X48
159 H  0X72  1   0X49
160 I  0X73  2   0X50
161 J  0X74  3   0X51
162 K  0X75  4   0X52
163 L  0X76  5   0X53
164 M  0X77  6   0X54
165 N  0X78  7   0X55
166 O  0X79  8   0X56
167 P  0X80  9   0X57
168 Q  0X81 ESC  0X1B
169 R  0X82 CTRL  0X11
170 S  0X83 SHIFT 0X10
171 T  0X84 ENTER 0XD
172 如果要使用组合键,则可以判断是否同时按下了这几个键,比如ctrl键、shift键以及alt键的组合使用就可以判断是否多按下了ctrl键、shift键以及alt键
Copy after login

The above is the detailed content of How to get keyboard content in js. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to type underline on the keyboard? How to type only underline without typing? How to type underline on the keyboard? How to type only underline without typing? Feb 22, 2024 pm 07:46 PM

Adjust the input method to English and hold down the Shift key and the minus key. Applicable model of the tutorial: Lenovo AIO520C System: Windows 10 Professional Edition: Microsoft Office Word 2022 Analysis 1 First check the Chinese and English typing of the input method and adjust it to English. 2Then hold down the Shift key and the Minus key on your keyboard at the same time. 3 Check the interface to see the underlined words. Supplement: How to quickly enter underline in Word document 1. If you need to enter an underline in Word, select the space with the mouse, then select the underline type in the font menu to enter. Summary/Notes: Be sure to change the input method to English before proceeding, otherwise the underscore cannot be successfully entered.

Keyboard auto-typing on Windows laptop Keyboard auto-typing on Windows laptop Feb 19, 2024 pm 05:33 PM

Computer input devices such as keyboard and mouse require human operation and cannot operate independently. The same goes for the touchpad and keyboard on Windows laptops. Text is not automatically entered, nor is the mouse clicked automatically. If something unusual happens, there must be a reason. If you encounter laptop keyboard auto-typing issues, follow the guide to fix it. Keyboard on Windows Laptop Typing Automatically When the keyboard on your Windows laptop is typing automatically, here’s how you can fix it. Check the keyboard manually Make sure the keyboard is working properly Check if the laptop is connected remotely Check if any autotyping programs are running Run a malware scan Adjust the keyboard settings Reinstall the keyboard driver Let’s know in detail

How to assign Copilot buttons on any keyboard in Windows 11 How to assign Copilot buttons on any keyboard in Windows 11 Feb 20, 2024 am 10:33 AM

Windows 11 computer keyboards that will be launched in the next few months will have a new Copilot key. This key allows users to easily enter co-pilot mode by pressing a designated button without upgrading a new PC. This guide will detail how to set up the copilot button on any Windows 11 keyboard. Microsoft recently announced that they have made important progress in advancing artificial intelligence-assisted driving. Windows 11 will add a dedicated Copilot key to further enhance the experience of PC users. This hardware change represents the first major upgrade to Windows PC keyboards in thirty years. In the coming months, new Windows 11 computers will feature a new Copilot key design on the keyboard

VGN co-branded 'Elden's Circle' keyboard and mouse series products are now on the shelves: Lani / Faded One custom theme, starting from 99 yuan VGN co-branded 'Elden's Circle' keyboard and mouse series products are now on the shelves: Lani / Faded One custom theme, starting from 99 yuan Aug 12, 2024 pm 10:45 PM

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

How to change the Microsoft Edge browser to open with 360 navigation - How to change the opening with 360 navigation How to change the Microsoft Edge browser to open with 360 navigation - How to change the opening with 360 navigation Mar 04, 2024 pm 01:50 PM

How to change the page that opens the Microsoft Edge browser to 360 navigation? It is actually very simple, so now I will share with you the method of changing the page that opens the Microsoft Edge browser to 360 navigation. Friends in need can take a look. I hope Can help everyone. Open the Microsoft Edge browser. We see a page like the one below. Click the three-dot icon in the upper right corner. Click "Settings." Click "On startup" in the left column of the settings page. Click on the three points shown in the picture in the right column (do not click "Open New Tab"), then click Edit and change the URL to "0" (or other meaningless numbers). Then click "Save". Next, select "

How to set the skin for the WeChat keyboard How to set the skin for the WeChat keyboard How to set the skin for the WeChat keyboard How to set the skin for the WeChat keyboard Mar 13, 2024 am 09:04 AM

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.

Maicong K87 three-mode mechanical keyboard adds 'hyacinth axis' and 'ice cream axis' version: Gasket structure, initial price starts at 299 yuan Maicong K87 three-mode mechanical keyboard adds 'hyacinth axis' and 'ice cream axis' version: Gasket structure, initial price starts at 299 yuan Feb 29, 2024 pm 05:00 PM

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.

How to set up handwriting input method on Apple mobile phone keyboard How to set up handwriting input method on Apple mobile phone keyboard Mar 08, 2024 pm 02:30 PM

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

See all articles