This example uses WinGetPhysKeyState to check the current state of the caps lock key; if it is depressed, a high pitch beep is emitted, while a low pitch beep is emitted if it is not depressed.

#define INCL_WININPUT     /* Window Input functions */
#define INCL_DOSPROCESS   /* OS/2 Process functions */
#include <os2.h>

LONG   lKeyState;         /* Key state              */
LONG   lScancode;         /* Scan code value        */

/* Get the physical key state for the caps lock key */
lScancode = 0x3a;
lKeyState = WinGetPhysKeyState(HWND_DESKTOP, lScancode);

/* Emit the high pitched beep if the caps lock is currently depressed; */
/* otherwise, emit a low pitched beep                                  */
if (lKeyState & 0x8000)
   DosBeep(1000,100L);
else
   DosBeep(200,100L);


[Back] [Next]