2 * Keyboard related functions
4 * Copyright 1993 Bob Amstadt
12 extern BOOL MouseButtonsStates[3];
13 extern BOOL AsyncMouseButtonsStates[3];
14 extern BYTE InputKeyStateTable[256];
15 BYTE AsyncKeyStateTable[256];
17 extern BYTE QueueKeyStateTable[256];
19 /**********************************************************************
20 * GetKeyState [USER.106]
21 * An application calls the GetKeyState function in response to a
22 * keyboard-input message. This function retrieves the state of the key
23 * at the time the input message was generated. (SDK 3.1 Vol 2. p 390)
25 INT GetKeyState(INT keycode)
29 if (keycode >= 'a' && keycode <= 'z')
33 retval = MouseButtonsStates[0];
35 retval = MouseButtonsStates[1];
37 retval = MouseButtonsStates[2];
39 retval = ( (INT)(QueueKeyStateTable[keycode] & 0x80) << 8 ) |
40 (INT)(QueueKeyStateTable[keycode] & 0x01);
43 dprintf_key(stddeb, "GetKeyState(%x) -> %x\n", keycode, retval);
47 /**********************************************************************
48 * GetKeyboardState [USER.222]
49 * An application calls the GetKeyboardState function in response to a
50 * keyboard-input message. This function retrieves the state of the keyboard
51 * at the time the input message was generated. (SDK 3.1 Vol 2. p 387)
53 void GetKeyboardState(BYTE *lpKeyState)
55 if (lpKeyState != NULL) {
56 QueueKeyStateTable[VK_LBUTTON] = MouseButtonsStates[0] >> 8;
57 QueueKeyStateTable[VK_MBUTTON] = MouseButtonsStates[1] >> 8;
58 QueueKeyStateTable[VK_RBUTTON] = MouseButtonsStates[2] >> 8;
59 memcpy(lpKeyState, QueueKeyStateTable, 256);
63 /**********************************************************************
64 * SetKeyboardState [USER.223]
66 void SetKeyboardState(BYTE *lpKeyState)
68 if (lpKeyState != NULL) {
69 memcpy(QueueKeyStateTable, lpKeyState, 256);
70 MouseButtonsStates[0] = QueueKeyStateTable[VK_LBUTTON]? 0x8000: 0;
71 MouseButtonsStates[1] = QueueKeyStateTable[VK_MBUTTON]? 0x8000: 0;
72 MouseButtonsStates[2] = QueueKeyStateTable[VK_RBUTTON]? 0x8000: 0;
76 /**********************************************************************
77 * GetAsyncKeyState (USER.249)
79 * Determine if a key is or was pressed. retval has high-order
80 * bit set to 1 if currently pressed, low-order bit set to 1 if key has
83 * This uses the variable AsyncMouseButtonsStates and
84 * AsyncKeyStateTable (set in event.c) which have the mouse button
85 * number or key number (whichever is applicable) set to true if the
86 * mouse or key had been depressed since the last call to
89 int GetAsyncKeyState(int nKey)
95 retval = AsyncMouseButtonsStates[0] |
96 MouseButtonsStates[0]? 0x0001: 0;
99 retval = AsyncMouseButtonsStates[1] |
100 MouseButtonsStates[1]? 0x0001: 0;
103 retval = AsyncMouseButtonsStates[2] |
104 MouseButtonsStates[2]? 0x0001: 0;
107 retval = AsyncKeyStateTable[nKey] |
108 (InputKeyStateTable[nKey] ? 0x8000 : 0);
112 memset( AsyncMouseButtonsStates, 0, 3 ); /* all states to false */
113 memset( AsyncKeyStateTable, 0, 256 );
115 dprintf_key(stddeb, "GetAsyncKeyState(%x) -> %x\n", nKey, retval);