home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / numlock3.zip / numlock.c next >
C/C++ Source or Header  |  1996-08-07  |  2KB  |  89 lines

  1. #define INCL_DOSFILEMGR
  2. #define INCL_DOSDEVICES
  3. #define INCL_DOSDEVIOCTL
  4. #define INCL_WININPUT
  5.  
  6. #include <os2.h>
  7. #include <stdio.h>
  8. #include <string.h>
  9.  
  10. HFILE hf;
  11. SHIFTSTATE ss;
  12. BYTE KeyState[257];
  13. BOOL bFlag;
  14. APIRET rc;
  15.  
  16.  
  17. int main ( int argc, char * argv[]) {    
  18.   void setnumlock(BOOL bSet);
  19.   
  20.   if (argc == 1) {
  21.      printf("You must either specify NUMLOCK ON or NUMLOCK OFF\n");
  22.      return 1;
  23.   }
  24.   else if (!strcmpi(argv[1],"ON") )   setnumlock(TRUE);
  25.   else if (!strcmpi(argv[1],"OFF"))   setnumlock(FALSE);
  26.   else
  27.      printf(" You must either specify NUMLOCK ON or NUMLOCK OFF");
  28.      
  29.  return 0;
  30. }
  31.  
  32.  
  33. void setnumlock(BOOL bSet)
  34. {
  35.   ULONG ulAction, ulLength;
  36.  
  37.   rc = DosOpen("KBD$",
  38.                &hf,
  39.                &ulAction,
  40.                0L,
  41.                0,
  42.                FILE_OPEN,
  43.                OPEN_ACCESS_READONLY|OPEN_SHARE_DENYNONE,
  44.                0);
  45.  
  46.   ulAction = 0;
  47.   ulLength = sizeof(ss);
  48.   rc = DosDevIOCtl(hf,
  49.                    IOCTL_KEYBOARD,
  50.                    KBD_GETSHIFTSTATE,
  51.                    0,
  52.                    0,
  53.                    &ulAction,
  54.                    &ss,
  55.                    sizeof(ss),
  56.                    &ulLength);
  57.  
  58.   WinSetKeyboardStateTable(HWND_DESKTOP, KeyState, FALSE);
  59.  
  60.   /* if bSet is true, enable NUMLOCK */
  61.   if(bSet)
  62.     {
  63.     KeyState[VK_NUMLOCK] |= 0x01;
  64.     ss.fsState |= NUMLOCK_ON;
  65.     }
  66.   else
  67.     {
  68.     KeyState[VK_NUMLOCK] &= ~0x01;
  69.     ss.fsState &= ~NUMLOCK_ON;
  70.     }
  71.  
  72.   WinSetKeyboardStateTable(HWND_DESKTOP, KeyState, TRUE);
  73.  
  74.   ulAction = sizeof(ss);
  75.   ulLength = 0;
  76.   rc = DosDevIOCtl(hf,
  77.                    IOCTL_KEYBOARD,
  78.                    KBD_SETSHIFTSTATE,
  79.                    &ss,
  80.                    sizeof(ss),
  81.                    &ulAction,
  82.                    0,
  83.                    0,
  84.                    &ulLength);
  85.  
  86.   rc = DosClose(hf);
  87. }
  88.  
  89.