Virtual Key Descriptions?

I know all the virtual keys are in the Windows API like this..
1
2
VK_MBUTTON = "Middle Mouse Button"
VK_KEY_G = "G"

But is there anything in the Windows API that can convert the key to a description automatically? I have been going through the list, writing an incredibly boring function that takes the VK_Key as a parameter and returns the description in a string. Surely there's an easier way than a giant switch statement?
You can write them to the file (by hands), and get it from there. It would be better, than giant switch statement.
Write them to the file? I'm using this in a tool to record keystrokes in a game for setting up external key bindings. I want to show the user their current binding and obviously no one will know what a hexadecimal or integer value represents. I don't think it's a very elegant solution to write the keystrokes to a file and get the key from there (I also don't entirely understand what you even mean by that in the first place.)
Last edited on
And what surprises you? Maybe you don't understand me: I meant to make a file like this:
keycodes.dat
0x0001 "Middle Mouse Button"
0x0002 "Left Mouse Button"
...
0x089 "A"
0x08A "B"
...

After the start of the program, you can download the data to a map, for example, and you can fast get it from it, and, what is better, you can change the codes or add extra only by changing the data file. If I were you, I would make so, as well as many other programmers.
(I also don't entirely understand what you even mean by that in the first place.)

What is that mysterious "that in the first place."? The idea?
Last edited on
I just didn't understand what you meant by write to a file and get from there. I figured you meant something along the lines of how you just described it but I wasn't sure. This is incredibly ridiculous in my opinion that there's nothing in the Windows API to accomplish this, surely there are thousands of programmers that have been in this situation before.

Ah, I guess I'm just going to have to write it all out manually. Whether it's in a file or hard coded doesn't really matter to me, I was just hoping that there was a function built in to get the description, as there is in C#. Maybe I'll release what I write so people can opt to just use my code instead of writing their own in the future.
Thanks, I just used the MSDN Documentation and another source that had some values MSDN didn't. I'm sure some keys are still missing but I finished writing the function and thought I would share it for those that find this link through a Google search. Please feel free to contribute any missing keys below and I will edit this post accordingly. I opted to use a giant switch statement just because it's universal and you can keep it internal.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
const char *CKeys::GetKeyName( int iKeyValue )
{
	switch( iKeyValue )
	{
	case 0xC1: // VK_ABNT_C1
		return "Abnt C1";
	case 0xC2: // VK_ABNT_C2
		return "Abnt C2";
	case VK_ADD:
		return "Numpad +";
	case VK_ATTN:
		return "Attn";
	case VK_BACK:
		return "Backspace";
		break;
	case VK_CANCEL:
		return "Break";
	case VK_CLEAR:
		return "Clear";
	case VK_CRSEL:
		return "Cr Sel";
		break;
	case VK_DECIMAL:
		return "Numpad .";
		break;
	case VK_DIVIDE:	
		return "Numpad /";
	case VK_EREOF:	
		return "Er Eof";
	case VK_ESCAPE:	
		return "Esc";
	case VK_EXECUTE:	
		return "Execute";
	case VK_EXSEL:	
		return "Ex Sel";
	case VK_ICO_CLEAR:	
		return "IcoClr";
	case VK_ICO_HELP:	
		return "IcoHlp";
	case VK_KEY_0:	
		return "0";
	case VK_KEY_1:	
		return "1";
	case VK_KEY_2:	
		return "2";
	case VK_KEY_3:	
		return "3";
	case VK_KEY_4:	
		return "4";
	case VK_KEY_5:	
		return "5";
	case VK_KEY_6:	
		return "6";
	case VK_KEY_7:	
		return "7";
	case VK_KEY_8:	
		return "8";
	case VK_KEY_9:	
		return "9";
	case VK_KEY_A:	
		return "A";
	case VK_KEY_B:	
		return "B";
	case VK_KEY_C:	
		return "C";
	case VK_KEY_D:	
		return "D";
	case VK_KEY_E:	
		return "E";
	case VK_KEY_F:	
		return "F";
	case VK_KEY_G:	
		return "G";
	case VK_KEY_H:	
		return "H";
	case VK_KEY_I:	
		return "I";
	case VK_KEY_J:	
		return "J";
	case VK_KEY_K:	
		return "K";
	case VK_KEY_L:	
		return "L";
	case VK_KEY_M:	
		return "M";
	case VK_KEY_N:	
		return "N";
	case VK_KEY_O:	
		return "O";
	case VK_KEY_P:	
		return "P";
	case VK_KEY_Q:	
		return "Q";
	case VK_KEY_R:	
		return "R";
	case VK_KEY_S:	
		return "S";
	case VK_KEY_T:	
		return "T";
	case VK_KEY_U:	
		return "U";
	case VK_KEY_V:	
		return "V";
	case VK_KEY_W:	
		return "W";
	case VK_KEY_X:	
		return "X";
	case VK_KEY_Y:	
		return "Y";
	case VK_KEY_Z:	
		return "Z";
	case VK_MULTIPLY:
		return "Numpad *";
	case VK_NONAME:
		return "NoName";
	case VK_NUMPAD0:
		return "Numpad 0";
	case VK_NUMPAD1:
		return "Numpad 1";
	case VK_NUMPAD2:
		return "Numpad 2";
	case VK_NUMPAD3:
		return "Numpad 3";
	case VK_NUMPAD4:
		return "Numpad 4";
	case VK_NUMPAD5:
		return "Numpad 5";
	case VK_NUMPAD6:
		return "Numpad 6";
	case VK_NUMPAD7:
		return "Numpad 7";
	case VK_NUMPAD8:
		return "Numpad 8";
	case VK_NUMPAD9:
		return "Numpad 9";
	case VK_PA1:
		return "Pa1";
	case VK_PACKET:
		return "Packet";
	case VK_PLAY:
		return "Play";
	case VK_PROCESSKEY:
		return "Process";
	case VK_RETURN:
		return "Enter";
	case VK_SELECT:
		return "Select";
	case VK_SEPARATOR:
		return "Separator";
	case VK_SPACE:
		return "Space";
	case VK_SUBTRACT:
		return "Num -";
	case VK_TAB:
		return "Tab";
	case VK_ZOOM:
		return "Zoom";
	case VK_ACCEPT:
		return "Accept";
	case VK_APPS:
		return "Context Menu";
	case VK_BROWSER_BACK:
		return "Browser Back";
	case VK_BROWSER_FAVORITES:
		return "Browser Favorites";
	case VK_BROWSER_FORWARD:
		return "Browser Forward";
	case VK_BROWSER_HOME:
		return "Browser Home";
	case VK_BROWSER_REFRESH:
		return "Browser Refresh";
	case VK_BROWSER_SEARCH:
		return "Browser Search";
	case VK_BROWSER_STOP:
		return "Browser Stop";
	case VK_CAPITAL:
		return "Caps Lock";
	case VK_CONVERT:
		return "Convert";
	case VK_DELETE:
		return "Delete";
	case VK_DOWN:
		return "Arrow Down";
	case VK_END:
		return "End";
	case VK_F1:
		return "F1";
	case VK_F10:
		return "F10";
	case VK_F11:
		return "F11";
	case VK_F12:
		return "F12";
	case VK_F13:
		return "F13";
	case VK_F14:
		return "F14";
	case VK_F15:
		return "F15";
	case VK_F16:
		return "F16";
	case VK_F17:
		return "F17";
	case VK_F18:
		return "F18";
	case VK_F19:
		return "F19";
	case VK_F2:
		return "F2";
	case VK_F20:
		return "F20";
	case VK_F21:
		return "F21";
	case VK_F22:
		return "F22";
	case VK_F23:
		return "F23";
	case VK_F24:
		return "F24";
	case VK_F3:
		return "F3";
	case VK_F4:
		return "F4";
	case VK_F5:
		return "F5";
	case VK_F6:
		return "F6";
	case VK_F7:
		return "F7";
	case VK_F8:
		return "F8";
	case VK_F9:
		return "F9";
	case VK_FINAL:
		return "Final";
	case VK_HELP:
		return "Help";
	case VK_HOME:
		return "Home";
	case VK_ICO_00:
		return "Ico00 *";
	case VK_INSERT:
		return "Insert";
	case VK_JUNJA:
		return "Junja";
	case VK_KANA:
		return "Kana";
	case VK_KANJI:
		return "Kanji";
	case VK_LAUNCH_APP1:
		return "App1";
	case VK_LAUNCH_APP2:
		return "App2";
	case VK_LAUNCH_MAIL:
		return "Mail";
	case VK_LAUNCH_MEDIA_SELECT:
		return "Media";
	case VK_LBUTTON:
		return "Left Button";
	case VK_LCONTROL:
		return "Left Ctrl";
	case VK_LEFT:
		return "Arrow Left";
	case VK_LMENU:
		return "Left Alt";
	case VK_LSHIFT:
		return "Left Shift";
	case VK_LWIN:
		return "Left Win";
	case VK_MBUTTON:
		return "Middle Button **";
	case VK_MEDIA_NEXT_TRACK:
		return "Next Track";
	case VK_MEDIA_PLAY_PAUSE:
		return "Play / Pause";
	case VK_MEDIA_PREV_TRACK:
		return "Previous Track";
	case VK_MEDIA_STOP:
		return "Stop";
	case VK_MODECHANGE:
		return "Mode Change";
	case VK_NEXT:
		return "Page Down";
	case VK_NONCONVERT:
		return "Non Convert";
	case VK_NUMLOCK:
		return "Num Lock";
	case VK_OEM_FJ_JISHO:
		return "isho";
	case VK_PAUSE:
		return "Pause";
	case VK_PRINT:
		return "Print";
	case VK_PRIOR:
		return "Page Up";
	case VK_RBUTTON:
		return "Right Button";
	case VK_RCONTROL:
		return "Right Ctrl";
	case VK_RIGHT:
		return "Arrow Right";
	case VK_RMENU:
		return "Right Alt";
	case VK_RSHIFT:
		return "Right Shift";
	case VK_RWIN:
		return "Right Win";
	case VK_SCROLL:
		return "Scroll Lock";
	case VK_SLEEP:
		return "Sleep";
	case VK_SNAPSHOT:
		return "Print Screen";
	case VK_UP:
		return "Arrow Up";
	case VK_VOLUME_DOWN:
		return "Volume Down";
	case VK_VOLUME_MUTE:
		return "Volume Mute";
	case VK_VOLUME_UP:
		return "Volume Up";
	case VK_XBUTTON1:
		return "X Button 1";
	case VK_XBUTTON2:
		return "X Button 2";
	default:
		return "Invalid Key";
	}
}
Last edited on
All breaks are useless, I think.
I haven't added breaks on all the keys yet, I will and I'll update it in a minute.

edit
Nevermind, silly mistake. :D
Last edited on
I'll repeat: All breaks are useless. It's not Pascal, after the 'return' the execution of the function is aborted and the value is returned. It won't go to the other cases.
Ahhh I see what you're saying. Silly mistake on my part, obviously after the value gets returned the function is aborted. I just have a very strong habit of putting break statements after each switch. Removed.
Last edited on
Removed.

VK_BACK, VK_CRSEL, VK_DECIMAL
Funny thing, I was looking for the exact same thing, I'll probably use your code until I find something better. You are missing the VK_OEM keys (like for the `/~ button etc.). ;)

S.
Topic archived. No new replies allowed.