FreeBASIC  0.91.0
io_multikey.c
Go to the documentation of this file.
1 /* multikey function for Windows console mode apps */
2 
3 #include "../fb.h"
4 #include <windows.h>
5 
6 const unsigned char __fb_keytable[][3] = {
7  { SC_ESCAPE, VK_ESCAPE, 0 }, { SC_1, '1', 0 },
8  { SC_2, '2', 0 }, { SC_3, '3', 0 },
9  { SC_4, '4', 0 }, { SC_5, '5', 0 },
10  { SC_6, '6', 0 }, { SC_7, '7', 0 },
11  { SC_8, '8', 0 }, { SC_9, '9', 0 },
12  { SC_0, '0', 0 }, { SC_MINUS, 0xBD, VK_SUBTRACT },
13  { SC_EQUALS, 0xBB, 0 }, { SC_BACKSPACE, VK_BACK, 0 },
14  { SC_TAB, VK_TAB, 0 }, { SC_Q, 'Q', 0 },
15  { SC_W, 'W', 0 }, { SC_E, 'E', 0 },
16  { SC_R, 'R', 0 }, { SC_T, 'T', 0 },
17  { SC_Y, 'Y', 0 }, { SC_U, 'U', 0 },
18  { SC_I, 'I', 0 }, { SC_O, 'O', 0 },
19  { SC_P, 'P', 0 }, { SC_LEFTBRACKET,0xDB, 0 },
20  { SC_RIGHTBRACKET,0xDD, 0 }, { SC_ENTER, VK_RETURN, 0 },
21  { SC_CONTROL, VK_CONTROL, 0 }, { SC_A, 'A', 0 },
22  { SC_S, 'S', 0 }, { SC_D, 'D', 0 },
23  { SC_F, 'F', 0 }, { SC_G, 'G', 0 },
24  { SC_H, 'H', 0 }, { SC_J, 'J', 0 },
25  { SC_K, 'K', 0 }, { SC_L, 'L', 0 },
26  { SC_SEMICOLON, 0xBA, 0 }, { SC_QUOTE, 0xDE, 0 },
27  { SC_TILDE, 0xC0, 0 }, { SC_LSHIFT, VK_SHIFT, 0 },
28  { SC_BACKSLASH, 0xDC, 0 }, { SC_Z, 'Z', 0 },
29  { SC_X, 'X', 0 }, { SC_C, 'C', 0 },
30  { SC_V, 'V', 0 }, { SC_B, 'B', 0 },
31  { SC_N, 'N', 0 }, { SC_M, 'M', 0 },
32  { SC_COMMA, 0xBC, 0 }, { SC_PERIOD, 0xBE, 0 },
33  { SC_SLASH, 0xBF, VK_DIVIDE }, { SC_RSHIFT, VK_SHIFT, 0 },
34  { SC_MULTIPLY, VK_MULTIPLY,0 }, { SC_ALT, VK_MENU, 0 },
35  { SC_SPACE, VK_SPACE, 0 }, { SC_CAPSLOCK, VK_CAPITAL, 0 },
36  { SC_F1, VK_F1, 0 }, { SC_F2, VK_F2, 0 },
37  { SC_F3, VK_F3, 0 }, { SC_F4, VK_F4, 0 },
38  { SC_F5, VK_F5, 0 }, { SC_F6, VK_F6, 0 },
39  { SC_F7, VK_F7, 0 }, { SC_F8, VK_F8, 0 },
40  { SC_F9, VK_F9, 0 }, { SC_F10, VK_F10, 0 },
41  { SC_NUMLOCK, VK_NUMLOCK, 0 }, { SC_SCROLLLOCK,VK_SCROLL, 0 },
42  { SC_HOME, VK_HOME, VK_NUMPAD7 }, { SC_UP, VK_UP, VK_NUMPAD8 },
43  { SC_PAGEUP, VK_PRIOR, VK_NUMPAD9 }, { SC_LEFT, VK_LEFT, VK_NUMPAD4 },
44  { SC_RIGHT, VK_RIGHT, VK_NUMPAD6 }, { SC_PLUS, VK_ADD, 0 },
45  { SC_END, VK_END, VK_NUMPAD1 }, { SC_DOWN, VK_DOWN, VK_NUMPAD2 },
46  { SC_PAGEDOWN, VK_NEXT, VK_NUMPAD3 }, { SC_INSERT, VK_INSERT, VK_NUMPAD0 },
47  { SC_DELETE, VK_DELETE, VK_DECIMAL }, { SC_F11, VK_F11, 0 },
48  { SC_F12, VK_F12, 0 }, { SC_LWIN, VK_LWIN, 0 },
49  { SC_RWIN, VK_RWIN, 0 }, { SC_MENU, VK_APPS, 0 },
50  { 0, 0, 0 }
51 };
52 
53 static HWND find_window()
54 {
55  TCHAR old_title[MAX_PATH];
56  TCHAR title[MAX_PATH];
57  static HWND hwnd = NULL;
58 
59  if (hwnd)
60  return hwnd;
61 
62  if (GetConsoleTitle(old_title, MAX_PATH)) {
63  sprintf(title, "_fb_console_title %f", fb_Timer());
64  SetConsoleTitle(title);
65  hwnd = FindWindow(NULL, title);
66  SetConsoleTitle(old_title);
67  }
68  return hwnd;
69 }
70 
71 int fb_hVirtualToScancode(int vkey)
72 {
73  int i;
74 
75  for (i = 0; __fb_keytable[i][0]; i++)
76  if ((__fb_keytable[i][2] == vkey) || (__fb_keytable[i][1] == vkey))
77  return __fb_keytable[i][0];
78  return 0;
79 }
80 
81 int fb_ConsoleMultikey( int scancode )
82 {
83  int i;
84 
85  if ( find_window() != GetForegroundWindow() )
86  return FB_FALSE;
87 
88  for( i = 0; __fb_keytable[i][0]; i++ ) {
89  if( __fb_keytable[i][0] == scancode ) {
90  return ((GetAsyncKeyState(__fb_keytable[i][1]) | GetAsyncKeyState(__fb_keytable[i][2])) & 0x8000) ? FB_TRUE : FB_FALSE;
91  }
92  }
93  return FB_FALSE;
94 }