7 #define KEY_BUFFER_LEN 512
27 { 0x001C, { 0x000D, 0x000D, 0x000A, 0xA600 } },
28 { 0x0035, { 0x002F, 0x003F, 0x9500, 0xA400 } },
29 { 0x0047, { 0x4700, 0x4700, 0x7700, 0x9700 } },
30 { 0x0048, { 0x4800, 0x4800, 0x8D00, 0x9800 } },
31 { 0x0049, { 0x4900, 0x4900, 0x8400, 0x9900 } },
32 { 0x004B, { 0x4B00, 0x4B00, 0x7300, 0x9B00 } },
33 { 0x004D, { 0x4D00, 0x4D00, 0x7400, 0x9D00 } },
34 { 0x004F, { 0x4F00, 0x4F00, 0x7500, 0x9F00 } },
35 { 0x0050, { 0x5000, 0x5000, 0x9100, 0xA000 } },
36 { 0x0051, { 0x5100, 0x5100, 0x7600, 0xA100 } },
37 { 0x0052, { 0x5200, 0x5200, 0x9200, 0xA200 } },
38 { 0x0053, { 0x5300, 0x5300, 0x9300, 0xA300 } }
41 #define FB_KEY_LIST_SIZE (sizeof(fb_ext_key_entries)/sizeof(FB_KEY_LIST_ENTRY))
44 { 0x0000, 0x0000, 0x0000, 0x0000 },
45 { 0x001B, 0x001B, 0x001B, 0x0100 },
46 { 0x0031, 0x0021, 0x0000, 0x7800 },
47 { 0x0032, 0x0040, 0x0300, 0x7900 },
49 { 0x0033, 0x0023, 0x0000, 0x7A00 },
50 { 0x0034, 0x0024, 0x0000, 0x7B00 },
51 { 0x0035, 0x0025, 0x0000, 0x7C00 },
52 { 0x0036, 0x005E, 0x001E, 0x7D00 },
54 { 0x0037, 0x0026, 0x001F, 0x7E00 },
55 { 0x0038, 0x002B, 0x0000, 0x7F00 },
56 { 0x0039, 0x0028, 0x0000, 0x8000 },
57 { 0x0030, 0x0029, 0x0000, 0x8100 },
59 { 0x002D, 0x005F, 0x001F, 0x8200 },
60 { 0x003D, 0x002B, 0x0000, 0x8300 },
61 { 0x0008, 0x0008, 0x007F, 0xE000 },
62 { 0x0009, 0x0F00, 0x9400, 0x0F00 },
64 { 0x0071, 0x0051, 0x0011, 0x1000 },
65 { 0x0077, 0x0057, 0x0017, 0x1100 },
66 { 0x0065, 0x0045, 0x0005, 0x1200 },
67 { 0x0072, 0x0052, 0x0012, 0x1300 },
69 { 0x0074, 0x0054, 0x0014, 0x1400 },
70 { 0x0079, 0x0059, 0x0019, 0x1500 },
71 { 0x0075, 0x0055, 0x0015, 0x1600 },
72 { 0x0069, 0x0049, 0x0009, 0x1700 },
74 { 0x006F, 0x004F, 0x000F, 0x1800 },
75 { 0x0070, 0x0050, 0x0010, 0x1900 },
76 { 0x005B, 0x007B, 0x001B, 0x1A00 },
77 { 0x005D, 0x007D, 0x001D, 0x1B00 },
79 { 0x000D, 0x000D, 0x000A, 0x1C00 },
80 { 0x0000, 0x0000, 0x0000, 0x0000 },
81 { 0x0061, 0x0041, 0x0001, 0x1E00 },
82 { 0x0073, 0x0053, 0x0013, 0x1F00 },
84 { 0x0064, 0x0044, 0x0004, 0x2000 },
85 { 0x0066, 0x0046, 0x0006, 0x2100 },
86 { 0x0067, 0x0047, 0x0007, 0x2200 },
87 { 0x0068, 0x0048, 0x0008, 0x2300 },
89 { 0x006A, 0x004A, 0x000A, 0x2400 },
90 { 0x006B, 0x004B, 0x000B, 0x2500 },
91 { 0x006C, 0x004C, 0x000C, 0x2600 },
92 { 0x003B, 0x003A, 0x0000, 0x2700 },
94 { 0x0027, 0x0022, 0x0000, 0x2800 },
95 { 0x0060, 0x007E, 0x0000, 0x2900 },
96 { 0x0000, 0x0000, 0x0000, 0x0000 },
97 { 0x005C, 0x007C, 0x001C, 0x0000 },
99 { 0x007A, 0x005A, 0x001A, 0x2C00 },
100 { 0x0078, 0x0058, 0x0018, 0x2D00 },
101 { 0x0063, 0x0043, 0x0003, 0x2E00 },
102 { 0x0076, 0x0056, 0x0016, 0x2F00 },
104 { 0x0062, 0x0042, 0x0002, 0x3000 },
105 { 0x006E, 0x004E, 0x000E, 0x3100 },
106 { 0x006D, 0x004D, 0x000D, 0x3200 },
107 { 0x002C, 0x003C, 0x0000, 0x3300 },
109 { 0x002E, 0x003E, 0x0000, 0x3400 },
110 { 0x002F, 0x003F, 0x0000, 0x3500 },
111 { 0x0000, 0x0000, 0x0000, 0x0000 },
112 { 0x002A, 0x0000, 0x0072, 0x0000 },
114 { 0x0000, 0x0000, 0x0000, 0x0000 },
115 { 0x0020, 0x0020, 0x0020, 0x0020 },
116 { 0x0000, 0x0000, 0x0000, 0x0000 },
117 { 0x3B00, 0x5400, 0x5E00, 0x6800 },
119 { 0x3C00, 0x5500, 0x5F00, 0x6900 },
120 { 0x3D00, 0x5600, 0x6000, 0x6A00 },
121 { 0x3E00, 0x5700, 0x6100, 0x6B00 },
122 { 0x3F00, 0x5800, 0x6200, 0x6C00 },
124 { 0x4000, 0x5900, 0x6300, 0x6D00 },
125 { 0x4100, 0x5A00, 0x6400, 0x6E00 },
126 { 0x4200, 0x5B00, 0x6500, 0x6F00 },
127 { 0x4300, 0x5C00, 0x6600, 0x7000 },
129 { 0x4400, 0x5D00, 0x6700, 0x7100 },
130 { 0x0000, 0x0000, 0x0000, 0x0000 },
131 { 0x0000, 0x0000, 0x0000, 0x0000 },
132 { 0x4700, 0x0037, 0x7700, 0x0000 },
134 { 0x4800, 0x0038, 0x8D00, 0x0000 },
135 { 0x4900, 0x0039, 0x8400, 0x0000 },
136 { 0x0000, 0x002D, 0x0000, 0x0000 },
137 { 0x4B00, 0x0034, 0x7300, 0x0000 },
139 { 0x4C00, 0x0035, 0x8F00, 0x4C00 },
140 { 0x4D00, 0x0036, 0x7400, 0x0000 },
141 { 0x0000, 0x002B, 0x0000, 0x0000 },
142 { 0x4F00, 0x0031, 0x7500, 0x0000 },
144 { 0x5000, 0x0032, 0x9100, 0x0000 },
145 { 0x5100, 0x0033, 0x7600, 0x0000 },
146 { 0x5200, 0x0030, 0x9200, 0x0000 },
147 { 0x5300, 0x002E, 0x9300, 0x0000 },
149 { 0x0000, 0x0000, 0x0000, 0x0000 },
150 { 0x0000, 0x0000, 0x0000, 0x0000 },
151 { 0x0000, 0x0000, 0x0000, 0x0000 },
152 { 0x8500, 0x8700, 0x8900, 0x8B00 },
154 { 0x8600, 0x8800, 0x8A00, 0x8C00 }
157 #define FB_KEY_CODES_SIZE (sizeof(fb_asc_key_codes)/sizeof(FB_KEY_CODES))
161 INPUT_RECORD *record;
170 memcpy( &record->Event.KeyEvent,
172 sizeof( KEY_EVENT_RECORD ) );
173 record->EventType = KEY_EVENT;
207 int do_remove = allow_remove;
250 DWORD dwEventsWritten = 0;
269 int ValidKeyStatus, ValidKeys, AddScratchPadKey =
FALSE;
270 if( event->bKeyDown ) {
273 event->wVirtualScanCode,
274 event->wVirtualKeyCode,
275 event->dwControlKeyState,
282 ((
event->dwControlKeyState & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED | SHIFT_PRESSED))==0)
283 && ((event->dwControlKeyState & (LEFT_ALT_PRESSED | RIGHT_ALT_PRESSED))!=0);
286 (
event->wVirtualScanCode >= 0x47 &&
event->wVirtualScanCode <= 0x49)
287 || (event->wVirtualScanCode >= 0x4b && event->wVirtualScanCode <= 0x4d)
288 || (
event->wVirtualScanCode >= 0x4f &&
event->wVirtualScanCode <= 0x52);
291 (
event->wVirtualKeyCode >= VK_NUMPAD0
292 &&
event->wVirtualKeyCode <= VK_NUMPAD9);
295 if( ValidKeys && ValidKeyStatus ) {
296 if( event->bKeyDown ) {
299 if( event->wVirtualScanCode <= 0x49 ) {
300 number =
event->wVirtualScanCode - 0x40;
301 }
else if( event->wVirtualScanCode <= 0x4d ) {
302 number =
event->wVirtualScanCode - 0x47;
303 }
else if( event->wVirtualScanCode <= 0x51 ) {
304 number =
event->wVirtualScanCode - 0x4e;
309 number =
event->wVirtualKeyCode - VK_NUMPAD0;
314 }
else if( KeyCode!=-1 ) {
316 }
else if( !ValidKeyStatus ) {
321 printf(
"%04hx\n", event->wVirtualScanCode);
322 printf(
"%04hx, %08x\n", event->wVirtualKeyCode, MapVirtualKey( event->wVirtualScanCode, 1));
323 printf(
"%02x\n", (
unsigned) (
unsigned char) event->uChar.AsciiChar);
327 if( AddScratchPadKey ) {
329 KEY_EVENT_RECORD rec;
330 SHORT wVkCode = VkKeyScan(chAsciiCode);
331 memset( &rec, 0,
sizeof(KEY_EVENT_RECORD) );
332 rec.uChar.AsciiChar = chAsciiCode;
333 rec.wVirtualKeyCode = wVkCode & 0xFF;
334 rec.dwControlKeyState |= (((wVkCode & 0x100)!=0) ? SHIFT_PRESSED : 0);
335 rec.dwControlKeyState |= (((wVkCode & 0x200)!=0) ? LEFT_CTRL_PRESSED : 0);
336 rec.dwControlKeyState |= (((wVkCode & 0x400)!=0) ? LEFT_ALT_PRESSED : 0);
337 rec.wVirtualScanCode = MapVirtualKey( rec.wVirtualKeyCode, 0 );
349 switch( dwCtrlType ) {
350 case CTRL_CLOSE_EVENT:
351 case CTRL_LOGOFF_EVENT:
352 case CTRL_SHUTDOWN_EVENT:
354 KEY_EVENT_RECORD rec;
355 memset( &rec, 0,
sizeof(KEY_EVENT_RECORD) );
356 rec.wVirtualKeyCode = VK_F4;
357 rec.dwControlKeyState = LEFT_ALT_PRESSED;
358 rec.wVirtualScanCode = MapVirtualKey( rec.wVirtualKeyCode, 0 );
388 int got_event =
FALSE;
403 switch ( ir.EventType ) {
405 if( ir.Event.KeyEvent.bKeyDown && ir.Event.KeyEvent.wRepeatCount != 0 ) {
407 }
else if( !ir.Event.KeyEvent.bKeyDown ) {
423 }
while( dwRead != 0 );
438 DWORD dwControlKeyState,
439 int bEnhancedKeysOnly
442 int KeyCode = 0, AddKeyCode =
FALSE;
443 int is_ext_code = AsciiChar==0;
446 if( (dwControlKeyState & ENHANCED_KEY)!=0 && is_ext_code) {
450 fb_ext_key_entries + i;
453 if( dwControlKeyState & (LEFT_ALT_PRESSED | RIGHT_ALT_PRESSED) ) {
455 AddKeyCode = KeyCode!=0;
456 }
else if( dwControlKeyState & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED) ) {
458 AddKeyCode = KeyCode!=0;
459 }
else if( dwControlKeyState & SHIFT_PRESSED ) {
461 AddKeyCode = KeyCode!=0;
470 unsigned uiAsciiChar = (unsigned) (
unsigned char) AsciiChar;
471 unsigned uiNormalKey, uiNormalKeyOtherCase;
476 uiNormalKey = MapVirtualKey( wVkCode, 2 ) & 0xFFFF;
477 if( isupper( (
int) uiNormalKey ) ) {
478 uiNormalKeyOtherCase = tolower( (
int) uiNormalKey );
479 }
else if( islower( (
int) uiNormalKey ) ) {
480 uiNormalKeyOtherCase = toupper( (
int) uiNormalKey );
482 uiNormalKeyOtherCase = uiNormalKey;
485 if( dwControlKeyState & (LEFT_ALT_PRESSED | RIGHT_ALT_PRESSED) ) {
487 }
else if( dwControlKeyState & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED) ) {
489 }
else if( dwControlKeyState & SHIFT_PRESSED ) {
492 if( uiAsciiChar==0 ) {
495 KeyCode = uiNormalKey;
505 AddKeyCode = (KeyCode > 255)
506 && ((uiAsciiChar==uiNormalKey) || (uiAsciiChar==uiNormalKeyOtherCase));
509 if( !AddKeyCode && !bEnhancedKeysOnly) {
512 KeyCode = uiAsciiChar;