home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / win_lrn / i_o / gkeybsta.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-08-11  |  1.5 KB  |  51 lines

  1. /*
  2.  *  GetKeyboardState
  3.  *  
  4.  *  This program demonstrates the use of the function GetKeyboardState.
  5.  *  This function copies the status of the 256 virtual-keyboard keys to the
  6.  *  buffer specified by the parameter.
  7.  *  
  8.  */
  9.  
  10. #include <windows.h>
  11.  
  12. int PASCAL WinMain(hInstance, hPrevInstance, lpszCmdLine, cmdShow)
  13. HANDLE hInstance, hPrevInstance;
  14. LPSTR  lpszCmdLine;
  15. int    cmdShow;
  16. {
  17.   static char szFuncName[] = "GetKeyboardState";
  18.   char rgcKeyState[256];
  19.   char szOutputBuffer1 [500];
  20.   int ncount, I;
  21.     
  22.   MessageBox(GetFocus(), (LPSTR)"Getting the state of the keyboard",
  23.              (LPSTR)szFuncName, MB_OK);
  24.  
  25.   (void)GetKeyboardState((LPSTR)rgcKeyState);
  26.  
  27.   if (rgcKeyState [VK_F1] & 0x80)
  28.      MessageBox(GetFocus(), (LPSTR)"The F1 key is Down",
  29.                 (LPSTR)szFuncName, MB_OK);
  30.   else
  31.      MessageBox(GetFocus (), (LPSTR)"The F1 Key is Up",
  32.                 (LPSTR)szFuncName, MB_OK);
  33.  
  34.   rgcKeyState [VK_F1] = 0x80;
  35.  
  36.   MessageBox (GetFocus (),(LPSTR)"The F1 key has been set to the down state.", 
  37.               (LPSTR)"About to use SetKeyboardState.", MB_OK);
  38.  
  39.   SetKeyboardState (rgcKeyState);
  40.   GetKeyboardState (rgcKeyState);
  41.  
  42.   if (rgcKeyState [VK_F1] & 0x80)
  43.      MessageBox(GetFocus(), (LPSTR)"The F1 key has been set successfully", 
  44.                 (LPSTR)"The F1 key is Down", MB_OK);
  45.   else
  46.      MessageBox(GetFocus(), (LPSTR)"The F1 was not set successfully",
  47.                 (LPSTR)"The F1 Key is Up", MB_OK);
  48.   return 0;
  49. }
  50.  
  51.