home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / numlock2.zip / numlock.cpp < prev    next >
C/C++ Source or Header  |  1996-08-06  |  3KB  |  101 lines

  1. /*
  2. From 121055711617@post2.tele.dkTue Aug  6 11:26:02 1996
  3. Date: Tue, 06 Aug 96 12:59:42 CET
  4. From: Jakob Havkrog <121055711617@post2.tele.dk>
  5. Reply to: Jacob Havkrog Joergensen <havkrog@post2.tele.dk>
  6. To: emarch@eagle.ais.net
  7. Subject: [Fwd: [Fwd: Re: NumLock. How do I set it with PM from BC+
  8.  
  9. For a PM app, you may skip the KBD$ part (i.e., just use the
  10. WinSetKeyboardStateTable part).
  11. -----------------------------------------------------------------------
  12. */
  13.  
  14. #define INCL_DOSFILEMGR
  15. #define INCL_DOSDEVICES
  16. #define INCL_DOSDEVIOCTL
  17. #define INCL_WININPUT
  18.  
  19. #include <os2.h>
  20. #include <stdio.h>
  21.  
  22. int main(int argc, char *argv[])
  23. {
  24.     HFILE hf;
  25.     SHIFTSTATE ss;
  26.     BYTE KeyState[257];
  27.     BOOL bFlag;
  28.     APIRET rc;
  29.  
  30.     ULONG ulAction, ulLength;
  31.  
  32.     rc = DosOpen("KBD$",
  33.                &hf,
  34.                &ulAction,
  35.                0L,
  36.                0,
  37.                FILE_OPEN,
  38.                OPEN_ACCESS_READONLY|OPEN_SHARE_DENYNONE,
  39.                0);
  40.  
  41.     ulAction = 0;
  42.     ulLength = sizeof(ss);
  43.     rc = DosDevIOCtl(hf,
  44.                    IOCTL_KEYBOARD,
  45.                    KBD_GETSHIFTSTATE,
  46.                    0,
  47.                    0,
  48.                    &ulAction,
  49.                    &ss,
  50.                    sizeof(ss),
  51.                    &ulLength);
  52.  
  53.     WinSetKeyboardStateTable(HWND_DESKTOP, KeyState, FALSE);
  54.  
  55.     int bSet = 0;
  56.     if(argc < 2)
  57.     {
  58.         printf("*** FreeWare! ***\n\n");
  59.         printf("\r\nUsage:   NUMLOCK  S[et] | R[eset]\n");
  60.         printf("Examples:     NUMLOCK S\n");
  61.         printf("Examples:     NUMLOCK Set\n");
  62.         printf("Examples:     NUMLOCK R\n");
  63.         printf("Examples:     NUMLOCK Reset\n");
  64.         printf("May be added to the config.sys as 'RUN=NUMLOCK Set'\n");
  65.         return(0);
  66.     }
  67.  
  68.     if(argc > 1 && (argv[1][0] == 'S' || argv[1][0] == 's') )
  69.     {
  70.         bSet = 1;
  71.     }
  72.  
  73.     /* if bSet is true, enable NUMLOCK */
  74.     if(bSet)
  75.     {
  76.         KeyState[VK_NUMLOCK] |= 0x01;
  77.         ss.fsState |= NUMLOCK_ON;
  78.     }
  79.     else
  80.     {
  81.         KeyState[VK_NUMLOCK] &= ~0x01;
  82.         ss.fsState &= ~NUMLOCK_ON;
  83.     }
  84.  
  85.     WinSetKeyboardStateTable(HWND_DESKTOP, KeyState, TRUE);
  86.  
  87.     ulAction = sizeof(ss);
  88.     ulLength = 0;
  89.     rc = DosDevIOCtl(hf,
  90.                    IOCTL_KEYBOARD,
  91.                    KBD_SETSHIFTSTATE,
  92.                    &ss,
  93.                    sizeof(ss),
  94.                    &ulAction,
  95.                    0,
  96.                    0,
  97.                    &ulLength);
  98.  
  99.     rc = DosClose(hf);
  100. }
  101.