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
330
|
{
fpGFX - Free Pascal Graphics Library
Copyright (C) 2000 - 2001 by
Areca Systems GmbH / Sebastian Guenther, sg@freepascal.org
Copyright (C) 2006 by Graeme Geldenhuys
member of the fpGFX development team.
Win32 GDI target implementation: Keycode translation helpers
See the file COPYING.modifiedLGPL, included in this distribution,
for details about the copyright.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
**********************************************************************}
function VirtKeyToKeycode(VirtKey: Byte): Word;
const
TranslTable: array[Byte] of Integer = (
-1, // $00
-1, // $01 VK_LBUTTON
-1, // $02 VK_RBUTTON
-1, // $03 VK_CANCEL
-1, // $04 VK_MBUTTON
-1, // $05 VK_XBUTTON1
-1, // $06 VK_XBUTTON2
-1, // $07
keyBackSpace, // $08 VK_BACK
keyTab, // $09 VK_TAB
-1, // $0a
-1, // $0b
keyClear, // $0c VK_CLEAR
keyReturn, // $0d VK_RETURN
-1, // $0e
-1, // $0f
keyShift, // $10 VK_SHIFT
keyCtrl, // $11 VK_CONTROL
keyAlt, // $12 VK_MENU
keyPause, // $13 VK_PAUSE
-1, // $14 VK_CAPITAL
-1, // $15 VK_KANA
-1, // $16
-1, // $17 VK_JUNJA
-1, // $18 VK_FINAL
-1, // $19 VK_HANJA
-1, // $1a
keyEscape, // $1b VK_ESCAPE
-1, // $1c VK_CONVERT
-1, // $1d VK_NONCONVERT
-1, // $1e VK_ACCEPT
keyModeSwitch, // $1f VK_MODECHANGE
$20, // $20 VK_SPACE
keyPrior, // $21 VK_PRIOR
keyNext, // $22 VK_NEXT
keyEnd, // $23 VK_END
keyHome, // $24 VK_HOME
keyLeft, // $25 VK_LEFT
keyUp, // $26 VK_UP
keyRight, // $27 VK_RIGHT
keyDown, // $28 VK_DOWN
keySelect, // $29 VK_SELECT
keyPrintScreen, // $2a VK_PRINT
keyExecute, // $2b VK_EXECUTE
keyPrintScreen, // $2c VK_SNAPSHOT
keyInsert, // $2d VK_INSERT
keyDelete, // $2e VK_DELETE
keyHelp, // $2f VK_HELP
$30, // $30 '0'
$31, // $31 '1'
$32, // $32 '2'
$33, // $33 '3'
$34, // $34 '4'
$35, // $35 '5'
$36, // $36 '6'
$37, // $37 '7'
$38, // $38 '8'
$39, // $39 '9'
-1, // $3a
-1, // $3b
-1, // $3c
-1, // $3d
-1, // $3e
-1, // $3f
-1, // $40
$41, // $41 'A'
$42, // $42 'B'
$43, // $43 'C'
$44, // $44 'D'
$45, // $45 'E'
$46, // $46 'F'
$47, // $47 'G'
$48, // $48 'H'
$49, // $49 'I'
$4a, // $4a 'J'
$4b, // $4b 'K'
$4c, // $4c 'L'
$4d, // $4d 'M'
$4e, // $4e 'N'
$4f, // $4f 'O'
$50, // $50 'P'
$51, // $51 'Q'
$52, // $52 'R'
$53, // $53 'S'
$54, // $54 'T'
$55, // $55 'U'
$56, // $56 'V'
$57, // $57 'W'
$58, // $58 'X'
$59, // $59 'Y'
$5a, // $5a 'Z'
-1, // $5b VK_LWIN
-1, // $5c VK_RWIN
-1, // $5d VK_APPS
-1, // $5e
-1, // $5f VK_SLEEP
keyP0, // $60 VK_NUMPAD0
keyP1, // $61 VK_NUMPAD1
keyP2, // $62 VK_NUMPAD2
keyP3, // $63 VK_NUMPAD3
keyP4, // $64 VK_NUMPAD4
keyP5, // $65 VK_NUMPAD5
keyP6, // $66 VK_NUMPAD6
keyP7, // $67 VK_NUMPAD7
keyP8, // $68 VK_NUMPAD8
keyP9, // $69 VK_NUMPAD9
keyPAsterisk, // $6a VK_MULTIPLY
keyPPlus, // $6b VK_ADD
keyPSeparator, // $6c VK_SEPARATOR
keyPMinus, // $6d VK_SUBTRACT
keyPDecimal, // $6e VK_DECIMAL
keyPSlash, // $6f VK_DIVIDE
keyF1, // $70 VK_F1
keyF2, // $71 VK_F2
keyF3, // $72 VK_F3
keyF4, // $73 VK_F4
keyF5, // $74 VK_F5
keyF6, // $75 VK_F6
keyF7, // $76 VK_F7
keyF8, // $77 VK_F8
keyF9, // $78 VK_F9
keyF10, // $79 VK_F10
keyF11, // $7a VK_F11
keyF12, // $7b VK_F12
keyF13, // $7c VK_F13
keyF14, // $7d VK_F14
keyF15, // $7e VK_F15
keyF16, // $7f VK_F16
keyF17, // $80 VK_F17
keyF18, // $81 VK_F18
keyF19, // $82 VK_F19
keyF20, // $83 VK_F20
keyF21, // $84 VK_F21
keyF22, // $85 VK_F22
keyF23, // $86 VK_F23
keyF24, // $87 VK_F24
-1, // $88
-1, // $89
-1, // $8a
-1, // $8b
-1, // $8c
-1, // $8d
-1, // $8e
-1, // $8f
keyNumLock, // $90 VK_NUMLOCK
keyScroll, // $91 VK_SCROLL
-1, // $92 VK_OEM_NEC_EQUAL
-1, // $93 VK_OEM_FJ_MASSHOU
-1, // $94 VK_OEM_FJ_TOUROKU
-1, // $95 VK_OEM_FJ_LOYA
-1, // $96 VK_OEM_FJ_ROYA
-1, // $97
-1, // $98
-1, // $99
-1, // $9a
-1, // $9b
-1, // $9c
-1, // $9d
-1, // $9e
-1, // $9f
keyShiftL, // $a0 VK_LSHIFT
keyShiftR, // $a1 VK_RSHIFT
keyCtrlL, // $a2 VK_LCONTROL
keyCtrlR, // $a3 VK_RCONTROL
-1, // $a4 VK_LMENU
-1, // $a5 VK_RMENU
-1, // $a6 VK_BROWSER_BACK
-1, // $a7 VK_BROWSER_FORWARD
-1, // $a8 VK_BROWSER_REFRESH
-1, // $a9 VK_BROWSER_STOP
-1, // $aa VK_BROWSER_SEARCH
-1, // $ab VK_BROWSER_FAVORITES
-1, // $ac VK_BROWSER_HOME
-1, // $ad VK_VOLUME_MUTE
-1, // $ae VK_VOLUME_DOWN
-1, // $af VK_VOLUME_UP
-1, // $b0 VK_MEDIA_NEXT_TRACK
-1, // $b1 VK_MEDIA_PREV_TRACK
-1, // $b2 VK_MEDIA_STOP
-1, // $b3 VK_MEDIA_PLAY_PAUSE
-1, // $b4 VK_LAUNCH_MAIL
-1, // $b5 VK_LAUNCH_MEDIA_SELECT
-1, // $b6 VK_LAUNCH_APP1
-1, // $b7 VK_LAUNCH_APP2
-1, // $b8
-1, // $b9
$dc, {U Umlaut} // $ba VK_OEM_1
$2b, {+ char} // $bb VK_OEM_PLUS
$2c, {, char} // $bc VK_OEM_COMMA
$2d, {- char} // $bd VK_OEM_MINUS
$2e, {. char} // $be VK_OEM_PERIOD
$23, {# char} // $bf VK_OEM_2
$d6, {O Umlaut} // $c0 VK_OEM_3
-1, // $c1
-1, // $c2
-1, // $c3
-1, // $c4
-1, // $c5
-1, // $c6
-1, // $c7
-1, // $c8
-1, // $c9
-1, // $ca
-1, // $cb
-1, // $cc
-1, // $cd
-1, // $ce
-1, // $cf
-1, // $d0
-1, // $d1
-1, // $d2
-1, // $d3
-1, // $d4
-1, // $d5
-1, // $d6
-1, // $d7
-1, // $d8
-1, // $d9
-1, // $da
-1, // $db VK_OEM_4
keyDeadCircumflex, // $dc VK_OEM_5
keyDeadAcute, // $dd VK_OEM_6
$c4, {A Umlaut} // $de VK_OEM_7
-1, // $df VK_OEM_8
-1, // $e0
-1, // $e1 VK_OEM_AX
$3c, {< char} // $e2 VK_OEM_102
-1, // $e3 VK_ICO_HELP
keyP5, // $e4 VK_ICO_00
-1, // $e5 VK_PROCESSKEY
-1, // $e6 VK_ICO_CLEAR
-1, // $e7 VK_PACKET
-1, // $e8
-1, // $e9 VK_OEM_RESET
-1, // $ea VK_OEM_JUMP
-1, // $eb VK_OEM_PA1
-1, // $ec VK_OEM_PA2
-1, // $ed VK_OEM_PA3
-1, // $ee VK_OEM_WSCTRL
-1, // $ef VK_OEM_CUSEL
-1, // $f0 VK_OEM_ATTN
-1, // $f1 VK_OEM_FINISH
-1, // $f2 VK_OEM_COPY
-1, // $f3 VK_OEM_AUTO
-1, // $f4 VK_OEM_ENLW
-1, // $f5 VK_OEM_BACKTAB
-1, // $f6 VK_ATTN
-1, // $f7 VK_CRSEL
-1, // $f8 VK_EXSEL
-1, // $f9 VK_EREOF
-1, // $fa VK_PLAY
-1, // $fb VK_ZOOM
-1, // $fc VK_NONAME
-1, // $fd VK_PA1
-1, // $fe VK_OEM_CLEAR
-1 // $ff
);
begin
if TranslTable[VirtKey] = -1 then
begin
{$IFDEF Debug}
WriteLn('No mapping for virtual keycode $', IntToHex(VirtKey, 2));
{$ENDIF}
Result := keyNIL
end else
begin
Result := TranslTable[VirtKey];
// WriteLn('Key $', IntToHex(VirtKey, 2), ' mapped to $', IntToHex(Result, 4));
end;
end;
function GetKeyboardShiftState: TShiftState;
var
State: array[Byte] of Byte;
begin
Windows.GetKeyboardState(State);
Result := [];
if (State[VK_SHIFT] and 128) <> 0 then
Include(Result, ssShift);
if (State[VK_MENU] and 128) <> 0 then
Include(Result, ssAlt);
if (State[VK_CONTROL] and 128) <> 0 then
Include(Result, ssCtrl);
if (State[VK_LBUTTON] and 128) <> 0 then
Include(Result, ssLeft);
if (State[VK_RBUTTON] and 128) <> 0 then
Include(Result, ssRight);
if (State[VK_MBUTTON] and 128) <> 0 then
Include(Result, ssMiddle);
if (State[VK_CAPITAL] and 1) <> 0 then
Include(Result, ssCaps);
if (State[VK_NUMLOCK] and 1) <> 0 then
Include(Result, ssNum);
if (State[VK_SCROLL] and 1) <> 0 then
Include(Result, ssScroll);
end;
{
$Log: gdikeys.inc,v $
Revision 1.2 2001/02/09 20:44:59 sg
* Fixed lots of keyboard mapping bugs
Revision 1.1 2001/01/11 23:07:24 sg
*** empty log message ***
}
|