home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / os / mswindo / programm / win32 / 847 < prev    next >
Encoding:
Text File  |  1992-09-08  |  1.5 KB  |  61 lines

  1. Newsgroups: comp.os.ms-windows.programmer.win32
  2. Path: sparky!uunet!franz.com!franz!jkf
  3. From: jkf@Franz.COM (Sean Foderaro)
  4. Subject: bug in SetKeyboardState?
  5. Message-ID: <JKF.92Sep6090948@frisky.Franz.COM>
  6. Sender: news@franz.com
  7. Nntp-Posting-Host: frisky
  8. Organization: Franz Inc., Berkeley, CA
  9. Date: Sun, 6 Sep 1992 17:09:48 GMT
  10. Lines: 49
  11.  
  12.  
  13.  I've written a little program to switch the Caps Lock and Control keys for 
  14. Windows 3.1 (which I'll be posting shortly).  I tried to port it to NT without 
  15. success.  I've traced the bug down to the SetKeyboardState function which 
  16. seems to have no effect in NT.  Perhaps this is due to a misunderstanding on 
  17. my part (or perhaps this just isn't implemented yet on NT).   
  18.  Here is a little test case.  Try compiling and running
  19. this under Windows 3.1 and you'll see your Caps Lock light flashing 
  20. when you run it.   Try it under NT and the Caps Lock light doesn't even
  21. change once.
  22.  
  23.  
  24. /* test case to see if SetKeyboardState is working */
  25. #include <windows.h>
  26.  
  27.  
  28. int FAR PASCAL WinMain(HINSTANCE hinstance, HINSTANCE hprevinstance,
  29.                         LPSTR cmdline, int cmdshow)
  30. {
  31.     unsigned char keybuf[256];
  32.     int i;
  33.     
  34.     GetKeyboardState(keybuf);
  35.     for (i = 0; i < 100; i++) {
  36.         keybuf[VK_CAPITAL] = 0;
  37.         SetKeyboardState(keybuf);
  38.         Sleep(500);
  39.         keybuf[VK_CAPITAL] = 0x81;
  40.         SetKeyboardState(keybuf);
  41.         Sleep(500);
  42.     }
  43. }
  44.  
  45. #ifndef WIN32
  46. void delay2() {}
  47.  
  48. Sleep(int msecs)
  49. {
  50.     /* just try to delay a bit */
  51.     int i;
  52.     for (i = 0; i< 10000; i++) delay2();
  53. }
  54.  
  55. #endif
  56.  
  57.  
  58.  
  59.  
  60.  
  61.