home *** CD-ROM | disk | FTP | other *** search
- From: lafaix@ibm.net (Martin Lafaix)
-
- Using DosDevIOCtl functions is not sufficient if you use PM: you also
- need to call WinSetKeyboardStateTable.
-
- #define INCL_DOSFILEMGR
- #define INCL_DOSDEVICES
- #define INCL_DOSDEVIOCTL
- #define INCL_WININPUT
-
- #include <os2.h>
- #include <stdio.h>
-
- VOID SetNumLockState(BOOL bSet) /* if bSet is true, enable NUMLOCK */
- {
- SHIFTSTATE ss;
- BYTE KeyState[257];
- BOOL bSet;
- APIRET rc;
- ULONG ulAction, ulLength;
- HFILE hf;
-
- rc = DosOpen("KBD$",
- &hf,
- &ulAction,
- 0L,
- 0,
- FILE_OPEN,
- OPEN_ACCESS_READONLY|OPEN_SHARE_DENYNONE,
- 0);
-
- /* reading keyboard state */
- ulAction = 0;
- ulLength = sizeof(ss);
- rc = DosDevIOCtl(hf,
- IOCTL_KEYBOARD,
- KBD_GETSHIFTSTATE,
- 0,
- 0,
- &ulAction,
- &ss,
- sizeof(ss),
- &ulLength);
-
- WinSetKeyboardStateTable(HWND_DESKTOP, KeyState, FALSE);
-
- /* changing state -- if bSet is true, enables NUMLOCK */
- if(bSet)
- {
- KeyState[VK_NUMLOCK] |= 0x01;
- ss.fsState |= NUMLOCK_ON;
- }
- else
- {
- KeyState[VK_NUMLOCK] &= ~0x01;
- ss.fsState &= ~NUMLOCK_ON;
- }
-
- /* seting keyboard state */
- WinSetKeyboardStateTable(HWND_DESKTOP, KeyState, TRUE);
-
- ulAction = sizeof(ss);
- ulLength = 0;
- rc = DosDevIOCtl(hf,
- IOCTL_KEYBOARD,
- KBD_SETSHIFTSTATE,
- &ss,
- sizeof(ss),
- &ulAction,
- 0,
- 0,
- &ulLength);
-
- rc = DosClose(hf);
- }
-