WinGetKeyState: Difference between revisions
Appearance
mNo edit summary |
|||
Line 11: | Line 11: | ||
:Contains the virtual key value in the low-order byte, and zero in the high-order byte. See remarks for possible values. | :Contains the virtual key value in the low-order byte, and zero in the high-order byte. See remarks for possible values. | ||
== | ==Returns== | ||
; lKeyState (LONG) - returns: Key state. | ; lKeyState (LONG) - returns: Key state. | ||
: This value is the OR combination of the following bits: | : This value is the OR combination of the following bits: |
Revision as of 20:15, 12 April 2024
This function returns the state of the key at the time that the last message obtained from the queue was posted.
Syntax
WinGetKeyState(hwndDeskTop, vkey)
Parameters
- hwndDeskTop (HWND) - input
- Desktop-window handle.
- HWND_DESKTOP - The desktop-window handle
- Other - Specified desktop-window handle.
- vkey (LONG) - input
- Virtual key value.
- Contains the virtual key value in the low-order byte, and zero in the high-order byte. See remarks for possible values.
Returns
- lKeyState (LONG) - returns
- Key state.
- This value is the OR combination of the following bits:
- 0x0001 - The key has been pressed an odd number of times since the system has been started.
- 0x8000 - The key is down.
Remarks
See also the WinGetPhysKeyState function. This function is used to determine whether a virtual key is up, down, or toggled.
This function can be used to obtain the state of the pointing device buttons with the VK_BUTTON1, VK_BUTTON2, and VK_BUTTON3 virtual key codes. The following are the possible values for the vkey parameter:
VK_BUTTON1 VK_BUTTON2 VK_BUTTON3 VK_ALT VK_ALTGRAF VK_CTRL VK_SHIFT VK_SPACE VK_BACKSPACE VK_TAB VK_BACKTAB VK_BREAK VK_PAUSE VK_NEWLINE VK_END VK_HOME VK_LEFT VK_UP VK_DOWN VK_RIGHT VK_PAGEDOWN VK_PAGEUP VK_DELETE VK_INSERT VK_CAPSLOCK VK_NUMLOCK VK_SCRLLOCK VK_PRINTSCRN VK_ENTER VK_ESC VK_SYSRO VK_ENDDRAG VK_CLEAR VK_EREOF VK_PA1 VK_ATTN VK_CRSEL VK_EXCEL VK_COPY VK_BLK1 VK_BLK2 VK_MENU VK_BIDI_FIRST VK_BIDI_LAST VK_DBCSFIRST VK_DBCSLAST VK_USERFIRST VK_USERLAST VK_F1 VK_F2 VK_F3 VK_F4 VK_F5 VK_F6 VK_F7 VK_F8 VK_F9 VK_F10 VK_F11 VK_F12 VK_F13 VK_F14 VK_F15 VK_F16 VK_F17 VK_F18 VK_F19 VK_F20 VK_F21 VK_F22 VK_F23 VK_F24
Errors
Possible returns from WinGetLastError
- PMERR_INVALID_HWND (0x1001)
- An invalid window handle was specified.
Example Code
This example uses WinGetKeyState to check if mouse button 1 was depressed when a WM_TIMER message was received. A high-pitched beep is emitted if it was depressed, and a low-pitched beep if it was not.
#define INCL_WININPUT /* Window Input functions */ #define INCL_DOSPROCESS /* OS/2 Process functions */ #include <os2.h> LONG lKeyState; /* Key state */ LONG vkey; /* Virtual key value */ case WM_TIMER: /* Get the key state of mouse button 1 */ vkey = VK_BUTTON1; lKeyState = WinGetKeyState(HWND_DESKTOP, vkey); /* Emit a high pitched beep if mouse button 1 is depressed */ /* when the timer message occurred; otherwise, emit a low */ /* pitched beep */ if (lKeyState & 0x8000) DosBeep(1000,100L); else DosBeep(200,100L);
Related Functions
- WinEnablePhysInput
- WinFocusChange
- WinGetPhysKeyState
- WinQueryFocus
- WinSetFocus
- WinSetKeyboardStateTable