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);


[Back] [Next]