JS judgment keyboard buttons

Source: Internet
Author: User

Judgment Method:

Table 3. DHTML Keyboard Events

Name

Description

Onkeypress

This event occurs when the user presses and releases any alphanumeric key. System buttons (for example, arrow keys and function keys) cannot be identified.

Onkeyup

This event occurs when the user releases any previously pressed keyboard keys.

Onkeydown

This event occurs when you press any keyboard key (including system buttons, such as the Arrow keys and function keys.

Example:

Function document. onkeydown ()
{
If (event. keycode = '39 ') //-> right arrow
{
Window. Open ("http://www.163.com ");
}
}

Function document. onkeypress ()
{
If (event. keycode = '43 ')
{
Alert ('+ "key you have entered the keyboard ');
}
}

When using JavaScript For Web keyboard event listening and capturing, it mainly uses onkeypress, onkeydown, and onkeyup events. The execution sequence of the three events is as follows: onkeydown-> onkeypress-> onkeyup. Generally, three keyboard events can be used to effectively respond to keyboard input. In actual use, we will find that these differences are different.

The onkeypress event cannot properly respond to system function keys (for example, back-up or deletion, but cannot effectively respond to Chinese Input Methods). Both onkeydown and onkeyup can effectively intercept system function keys, however, you can select different Keyboard Events based on the actual situation.
Because onkeypress cannot capture system function keys. the keycode attribute of the event object is different from the keycode attribute obtained in the onkeyup and onkeyup Keyboard Events, mainly because the keycode of the onkeypress event is case sensitive to letters, while the onkeydown and onkeyup events are not sensitive; the keycode of the onkeypress event cannot distinguish between the number keys on the primary key disk and the number keys on the pay keyboard. the keycode of onkeydown and onkeyup is sensitive to the number keys on the master and pay keyboard.
Http://liu2liu2.spaces.live.com/blog/cns! 54b12917375ef5a0! 270. Entry

Blocked key combination Ctrl + n

ASCIICode

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

ASCII code

Keyboard

ASCII code

Keyboard

ASCII code

Keyboard

ASCII code

Keyboard

27

ESC

32

Space

33

!

34

"

35

#

36

$

37

%

38

&

39

'

40

(

41

)

42

*

43

+

44

'

45

-

46

.

47

/

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

[

92

\

93

]

94

^

95

_

96

`

97

A

98

B

99

C

100

D

101

E

102

F

103

G

104

H

105

I

106

J

107

K

108

L

109

M

110

N

111

O

112

P

113

Q

114

R

115

S

116

T

117

U

118

V

119

W

120

X

121

Y

122

Z

123

{

124

|

125

}

126

~

 

 

 

The ASCII code (keycode) corresponding to the keyboard number)

Keycode 1 = left mouse button
Keycode 2 = right-click
Keycode 3 = Cancel
Keycode 4 = middle mouse buttons
Keycode 8 = backspace
Keycode 9 = Tab
Keycode 12 = clear (unknown)
Keycode 13 = enter
Keycode 16 = shift_l
Keycode 17 = control_l
Keycode 18 = alt_l
Keycode 19 = pause
Keycode 20 = caps_lock
Keycode 27 = escape
Keycode 32 = space
Keycode 33 = prior (Pageup key)
Keycode 34 = next (Pagedown key)
Keycode 35 = end
Keycode 36 = home
Keycode 37 = left
Keycode 38 = up
Keycode 39 = right
Keycode 40 = down
Keycode 41 = select (unknown)
Keycode 42 = Print (printscreen key)
Keycode 43 = execute (unknown)
Keycode 45 = insert
Keycode 46 = Delete
Keycode 47 = help (unknown)
Keycode 48 = 0 equal braceright
Keycode 49 = 1 exclam onesuperior
Keycode 50 = 2 quotedbl twosuperior
Keycode 51 = 3 Section threesuperior
Keycode 52 = 4 dollar
Keycode 53 = 5 percent
Keycode 54 = 6 ampersand
Keycode 55 = 7 slash braceleft
Keycode 56 = 8 parenleft bracketleft
Keycode 57 = 9 parenright bracketright
Keycode 65 =
Keycode 66 = B
Keycode 67 = C
Keycode 68 = d
Keycode 69 = e eurosign
Keycode 70 = f
Keycode 71 = g
Keycode 72 = H
Keycode 73 = I
Keycode 74 = J
Keycode 75 = K
Keycode 76 = L
Keycode 77 = m mu
Keycode 78 = n
Keycode 79 = o
Keycode 80 = p
Keycode 81 = Q
Keycode 82 = r
Keycode 83 = s
Keycode 84 = t
Keycode 85 = u
Keycode 86 = V v
Keycode 87 = W
Keycode 88 = x
Keycode 89 = y
Keycode 90 = z
Keycode 96 = kp_0 kp_0 (keypad number 0)
Keycode 97 = kp_1 kp_1 (keypad number 1)
Keycode 98 = kp_2 kp_2 (keypad Number 2)
Keycode 99 = kp_3 kp_3 (keypad number 3)
Keycode 100 = kp_4 kp_4 (keypad number 4)
Keycode 101 = kp_5 kp_5 (keypad number 5)
Keycode 102 = kp_6 kp_6 (keypad number 6)
Keycode 103 = kp_7 kp_7 (keypad number 7)
Keycode 104 = kp_8 kp_8 (keypad number 8)
Keycode 105 = kp_9 kp_9 (keypad number 9)
Keycode 106 = kp_multiply (keypad multiplication)
Keycode 107 = kp_add (keypad plus)
Keycode 108 = kp_separator (keypad return key)
Keycode 109 = kp_subtract (keypad subtraction)
Keycode 110 = kp_decimal (keypad decimal point)
Keycode 111 = kp_divide (keypad Division)
Key code 112 = F1
Keycode 113 = F2
Key code 114 = F3
Keycode 115 = F4
Key code 116 = F5
Keycode 117 = F6
Key code 118 = F7
Key code 119 = F8
Keycode 120 = F9
Keycode 121 = F10
Keycode 122 = F11
Key Code 123 = F12
Keycode 124 = f13
Keycode 125 = F14
Keycode 126 = F15
Keycode 127 = F16
Keycode 128 = f17
Keycode 129 = F18
Keycode 130 = F19
Keycode 131 = F20
Keycode 132 = F21
Keycode 133 = f22
Keycode 134 = F23
Keycode 135 = f24
Keycode 136 = num_lock
Keycode 137 = scroll_lock (unknown)
Key code 187 = acute grave (unknown)
Keycode 188 = comma semicolon (unknown) (semicolon)
Keycode 189 = minus underscore (underline)
Keycode 190 = period colon (unknown colon)
Keycode 192 = numbersign apostrophe (unknown single quotes)
Key Code 210 = plusminus hyphen macron (unknown & ^)
Key code 211 =
Key code 212 = copyright registered (unknown)
Key code 213 = guillemotleft guillemotright (unknown)
Keycode 214 = masculine ordfeminine (unknown)
Keycode 215 = AE AE (unknown)
Key code 216 = cent yen (unknown)
Key code 217 = questiondown exclamdown (unknown)
Key code 218 = onequarter onehalf threequarters (unknown)
Keycode 220 = less greater bar (less than the number greater than the number unknown)
Keycode 221 = plus asterisk asciitilde (the plus Asterisk is unknown)
Keycode 227 = multiply Division (multiplication and division)
Keycode 228 = acircumflex (unknown)
Key code 229 = ecircumflex (unknown)
Keycode 230 = icircumflex (unknown)
Key code 231 = ocircumflex (unknown)
Key code 232 = ucircumflex (unknown)
Key code 233 = ntilde (unknown)
Keycode 234 = yacute (unknown)
Key code 235 = Oslash ooblique (unknown)
Key Code 236 = aring (unknown)
Keycode 237 = ccedilla (unknown)
Key code 238 = thorn (unknown)
Keycode 239 = ETH Eth (unknown)
Key code 240 = diaeresis cedilla currency (unknown)
Key code 241 = agrave atilde (unknown)
Keycode 242 = egrave (unknown)
Keycode 243 = igrave (unknown)
Key code 244 = ograve otilde (unknown)
Keycode 245 = ugrave (unknown)
Keycode 246 = adiaeresis (unknown)
Key code 247 = ediaeresis (unknown)
Keycode 248 = idiaeresis (unknown)
Keycode 249 = odiaeresis (unknown)
Keycode 250 = udiaeresis (unknown)
Key code 251 = ssharp question backslash (unknown)
Key code 252 = asciicircum degree (unknown)
Key code 253 = 3 Sterling (unknown)
Keycode 254 = mode_switch (unknown)

If you want to use the combination key, you can use event. ctrlkey, event. shiftkey, and event. altkey to determine whether the Ctrl, shift, and ALT keys are pressed.

Example: event. ctrlkey = true & event. keycode = 65

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.