Jump to content

WinSetKeyboardStateTable: Difference between revisions

From EDM2
No edit summary
No edit summary
Line 2: Line 2:


==Syntax==
==Syntax==
 WinSetKeyboardStateTable(hwndDeskTop, abKeyStateTable, fSet)
WinSetKeyboardStateTable(hwndDeskTop, abKeyStateTable, fSet)


==Parameters==
==Parameters==

Revision as of 16:46, 9 April 2025

This function gets or sets the keyboard state.

Syntax

WinSetKeyboardStateTable(hwndDeskTop, abKeyStateTable, fSet)

Parameters

hwndDeskTop (HWND) - Input
Desktop-window handle.
HWND_DESKTOP
The desktop-window handle
Other
Specified desktop-window handle.
abKeyStateTable (PBYTE) - In/Out
Key state table.
This is a 256-byte table indexed by virtual key value.
For any virtual key, the 0x80 bit is set if the key is down, and zero if it is up. The 0x01 bit is set if the key is toggled, (pressed an odd number of times), otherwise it is zero.
fSet (BOOL) - Input
Set indicator.
TRUE
The keyboard state is set from abKeyStateTable
FALSE
The keyboard state is copied to abKeyStateTable.

Returns

rc (BOOL) - returns
Success indicator.
TRUE
Successful completion
FALSE
Error occurred.

Remarks

This function does not change the physical state of the keyboard, but changes the value returned by WinGetKeyState, not WinGetPhysKeyState. To set the state of a single key, first get the entire table, modify the individual key, and then set the table from the modified value.

Errors

Possible returns from WinGetLastError:

  • PMERR_INVALID_HWND (0x1001) An invalid window handle was specified.

Example Code

#define INCL_WININPUT
#include <OS2.H>
BYTE KeyState[256]; /* This is a 256 byte table   */
                    /* indexed by virtual key     */
                    /* value.                     */
                    /* For any virtual key, the   */
                    /* 0x80 bit is set if the key */
                    /* is down, and zero if it is */
                    /* up.  The 0x01 bit is set   */
                    /* if the key is toggled,     */
                    /* (pressed an odd number     */
                    /* of times), otherwise it is */
                    /* zero.                      */
WinSetKeyboardStateTable(HWND_DESKTOP,
                         KeyState,
                         FALSE); /* get a copy of the keyboard */
                                 /* state.                     */
KeyState[VK_CAPSLOCK] |= 0x01;   /* set the CAPSLOCK key to    */
                                 /* on state           */
WinSetKeyboardStateTable(HWND_DESKTOP,
                         KeyState,
                         TRUE); /* set the keyboard state */

Related Functions