-1

Is there a list of the keycodes returned by VB.NET and C# in the .KeyDown event?

The values returned don't match the usual ASCII codes.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
David Wilson
  • 4,369
  • 3
  • 18
  • 31

3 Answers3

7

These values are all part of the Keys Enumeration.

The actual values of these (as with all Enums) are arbitrary, so you should never write code that compares this to a numeric value. They could possibly change value with a framework update for example.

It just so happens the A-Z correspond to the ASCII values for A-Z, but again you shouldn't rely on this.

Intellisense shows you these keys (with each individual value) when appropriate:

enter image description here

And you can also search in the object browser (F11) for Windows.System.Forms.Keys and you will see the full list (with values):

enter image description here

Matt Wilko
  • 26,994
  • 10
  • 93
  • 143
3

0 No key pressed

1 The LEFT MOUSE Button

2 The RIGHT MOUSE Button

3 CANCEL KEY

4 The MIDDLE MOUSE Button (three-button mouse)

5 The first x mouse button (five-button mouse)

6 The second x mouse button (five-button mouse)

7 Undefined

8 BACKSPACE

9 TAB

10 The LINEFEED key

11 Undefined

12 CLEAR key

13 RETURN/ENTER KEY (next to letters) also ENTER KEY (on number-pad)

14 Undefined

15 Undefined

16 SHIFT

17 CTRL

18 ALT

19 PAUSE / BREAK

20 CAPS LOCK

21 The IME Hanguel mode key / The IME Kana mode key

22 Undefined

23 The IME Junja mode key

24 The IME final mode key

25 The IME Hanja mode key / The IME Kanji mode key

26 Undefined

27 ESC

28 The IME convert key

29 The IME nonconvert key

30 The IME accept key

31 The IME mode change key

32 SPACE BAR

33 PAGE UP / PGUP KEY

34 PAGE DOWN / PGDN KEY

35 END

36 HOME

37 LEFT ARROW KEY

38 UP ARROW KEY

39 RIGHT ARROW KEY

40 DOWN ARROW KEY

41 The SELECT key

42 The PRINT key

43 The EXECUTE key

44 The PRINT SCREEN key

45 INSERT

46 DELETE

47 The HELP key

48 0/) KEY ON KEYBOARD (above letters)

49 1/! KEY ON KEYBOARD (above letters)

50 2/@ KEY ON KEYBOARD (above letters)

51 3/# KEY ON KEYBOARD (above letters)

52 4/$ KEY ON KEYBOARD (above letters)

53 5/% KEY ON KEYBOARD (above letters)

54 6/^ KEY ON KEYBOARD (above letters)

55 7/& KEY ON KEYBOARD (above letters)

56 8/* KEY ON KEYBOARD (above letters)

57 9/( KEY ON KEYBOARD (above letters)

58 Undefined

59 Undefined

60 Undefined

61 Undefined

62 Undefined

63 Undefined

64 Undefined

65 A and a KEY

66 B and b KEY

67 C and c KEY

68 D and d KEY

69 E and e KEY

70 F and f KEY

71 G and g KEY

72 H and h KEY

73 I and i KEY

74 J and j KEY

75 K and k KEY

76 L and l KEY

77 M and m KEY

78 N and n KEY

79 O and o KEY

80 P and p KEY

81 Q and q KEY

82 R and r KEY

83 S and s KEY

84 T and t KEY

85 U and u KEY

86 V and v KEY

87 W and w KEY

88 X and x KEY

89 Y and y KEY

90 Z and z KEY

91 The left Windows logo key

92 The right Windows logo key

93 CONTEXT-MENU KEY (KEY WHICH SIMULATES A RIGHT-MOUSE CLICK)

94 Reserved

95 SLEEP/STANDBY KEY ON KEYBOARD

96 0 KEY (on number-pad)

97 1 KEY (on number-pad)

98 2 KEY (on number-pad)

99 3 KEY (on number-pad)

100 4 KEY (on number-pad)

101 5 KEY (on number-pad)

102 6 KEY (on number-pad)

103 7 KEY (on number-pad)

104 8 KEY (on number-pad)

105 9 KEY (on number-pad)

106 * KEY (on number-pad)

107 + KEY (on number-pad)

108 The separator key (ENTER key on number-pad)

109 - KEY (on number-pad)

110 . KEY (on number-pad)

111 / KEY (on number-pad)

112 F1

113 F2

114 F3

115 F4

116 F5

117 F6

118 F7

119 F8

120 F9

121 F10

122 F11

123 F12

124 F13

125 F14

126 F15

127 F16

128 F17

129 F18

130 F19

131 F20

132 F21

133 F22

134 F23

135 F24

136 Unassigned

137 Unassigned

138 Unassigned

139 Unassigned

140 Unassigned

141 Unassigned

142 Unassigned

143 Unassigned

144 NUM LOCK

145 SCROLL LOCK

146 OEM specific

147 OEM specific

148 OEM specific

149 OEM specific

150 OEM specific

151 Unassigned

152 Unassigned

153 Unassigned

154 Unassigned

155 Unassigned

156 Unassigned

157 Unassigned

158 Unassigned

159 Unassigned

160 The left SHIFT key

161 The right SHIFT key

162 The left CTRL key

163 The right CTRL key

164 The left ALT key

165 The right ALT key

166 BROWSER BACK KEY ON KEYBOARD / INTERNET-CONTROL (Windows 2000 or later)

167 BROWSER FORWARD KEY ON KEYBOARD / INTERNET-CONTROL (Windows 2000 or later)

168 BROWSER REFRESH KEY ON KEYBOARD / INTERNET-CONTROL (Windows 2000 or later)

169 BROWSER STOP KEY ON KEYBOARD / INTERNET-CONTROL (Windows 2000 or later)

170 BROWSER SEARCH KEY ON KEYBOARD / INTERNET-CONTROL (Windows 2000 or later)

171 BROWSER FAVORITES KEY ON KEYBOARD / INTERNET-CONTROL (Windows 2000 or later)

172 BROWSER HOME KEY ON KEYBOARD / INTERNET-CONTROL (Windows 2000 or later)

173 MUTE KEY ON KEYBOARD / MEDIA-CONTROL (Windows 2000 or later)

174 VOLUME DOWN KEY ON KEYBOARD / MEDIA-CONTROL (Windows 2000 or later)

175 VOLUME UP KEY ON KEYBOARD / MEDIA-CONTROL (Windows 2000 or later)

176 The media next track key (Windows 2000 or later)

177 The media previous track key (Windows 2000 or later)

178 The media Stop key (Windows 2000 or later)

179 The media play pause key (Windows 2000 or later)

180 The launch mail key / E-MAIL KEY ON KEYBOARD / INTERNET-CONTROL (Windows 2000 or later)

181 The select media key / MEDIA KEY ON KEYBOARD / MEDIA-CONTROL (Windows 2000 or later)

182 The start application one key (Windows 2000 or later)

183 The start application two key (Windows 2000 or later)

184 Reserved

185 Reserved

186 ; and : KEY

187 =/+ KEY ON KEYBOARD (above letters)

188 , and < KEY

189 -/_ KEY ON KEYBOARD (above letters)

190 . and > KEY

191 / and ? KEY

192 ~ and ` KEY ON KEYBOARD

193 Reserved

194 Reserved

195 Reserved

196 Reserved

197 Reserved

198 Reserved

199 Reserved

200 Reserved

201 Reserved

202 Reserved

203 Reserved

204 Reserved

205 Reserved

206 Reserved

207 Reserved

208 Reserved

209 Reserved

210 Reserved

211 Reserved

212 Reserved

213 Reserved

214 Reserved

215 Reserved

216 Unassigned

217 Unassigned

218 Unassigned

219 [ and { KEY

220 \ and | KEY

221 ] and } KEY

222 ' and # KEY

223 Used for miscellaneous characters; it can vary by keyboard

224 Reserved

225 OEM specific

226 The OEM angle bracket or backslash key on the RT 102 key keyboard (Windows 2000 or later)

227 OEM specific

228 OEM specific

229 The PROCESS KEY key (IME PROCESS KEY)

230 Oem specific

231 Used to pass Unicode characters as if they were keystrokes (Windows 2000 or later)

232 Unassigned

233 OEM specific

234 OEM specific

235 OEM specific

236 OEM specific

237 OEM specific

238 OEM specific

239 OEM specific

240 OEM specific

241 OEM specific

242 OEM specific

243 OEM specific

244 OEM specific

245 OEM specific

246 The ATTN key

247 The CRSEL key

248 The EXSEL key

249 The ERASE EOF key

250 The PLAY key

251 The ZOOM key

252 Reserved for future use

253 The PA1 key

254 The CLEAR key

255 OTHER / MISC KEY ON KEYBOARD

David Wilson
  • 4,369
  • 3
  • 18
  • 31
0

You can use Keys.xx where xx is from the following list:

Keys Enum.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Leonid Malyshev
  • 475
  • 1
  • 6
  • 14