home *** CD-ROM | disk | FTP | other *** search
/ The Pier Shareware 6 / The_Pier_Shareware_Number_6_(The_Pier_Exchange)_(1995).iso / 035 / cenvi29.zip / NUMLOCK.CMD < prev    next >
OS/2 REXX Batch file  |  1994-03-08  |  5KB  |  126 lines

  1. EXTPROC CENVI
  2. /****************************************************************************
  3.  *** NumLock.cmd - Turn ON NUMLOCK for this session and for all sessions. ***
  4.  *** ver.1         This program, or a shadow of it, can be included in    ***
  5.  ***               your OS/2 startup folder if you want NumLock on as     ***
  6.  ***               a default when you turn on your computer.              ***
  7.  ***                                                                      ***
  8.  ***               If you run with a second parameter, then that is the   ***
  9.  ***               wait interval and this program runs forever setting    ***
  10.  ***               the numlock key at that interval.                      ***
  11.  ****************************************************************************/
  12.  
  13.  
  14. main(argc,argv)
  15. {
  16.    if ( argc != 1  &&  0 == (WaitInterval = atoi(argv[1])) ) {
  17.       ShowInstructions();
  18.    } else {
  19.       SetLocalKeyboardStatus();
  20.       SetGlobalKeyboardTable();
  21.       if ( 1 != argc ) {
  22.          // kill the resident if it's already running
  23.          system("kill \"%s\"",WindowTitle);
  24.          // install the resident version of this program
  25.          system("start \"%s\" /N /B /WIN /MIN CEnvi #include '%s,,,/*RESIDENT*/' Forever(%d)",
  26.                 WindowTitle,argv[0],WaitInterval);
  27.       }
  28.    }
  29. }
  30.  
  31. ShowInstructions()
  32. {
  33.    printf("\a\n");
  34.    printf("NumLock.cmd - Set the NumLock key ON for OS/2 sessions and for the WPS.\n");
  35.    printf("\n");
  36.    printf("SYNTAX: NumLock [Interval]\n");
  37.    printf("\n");
  38.    printf("Where:   Interval - Optional period to suspend, without taking processor\n");
  39.    printf("                    time, before setting the NUMLOCK key again. If this\n");
  40.    printf("                    is not supplied or is 0 then will only set NUMLOCK\n");
  41.    printf("                    once and then exit. Time is in milliseconds. You may\n");
  42.    printf("                    want to set this process looping every second, or so,\n");
  43.    printf("                    if you need to keep NUMLOCK reset after a full-screen\n");
  44.    printf("                    session has undone it.\n");
  45.    printf("\n");
  46.    printf("Example: NumLock         - sets NumLock only once\n");
  47.    printf("         NumLock 1000    - sets NumLock once every second\n");
  48.    printf("\n");
  49. }
  50.  
  51. #define  NUMLOCK_BIT    0x20
  52.  
  53. SetLocalKeyboardStatus()  // set NUMLOCK on for local session
  54. {
  55.    // Open $Kbd device
  56.    #define ORD_DOS32OPEN   273
  57.    DynamicLink("doscalls",ORD_DOS32OPEN,BIT32,CDECL,
  58.                "\\DEV\\KBD$",FileHandle,ActionTaken,0,
  59.                0,0x01,0x40,0);
  60.  
  61.    // call DosDevIOCTL to get kbd state
  62.    #define ORD_DOS32DEVIOCTL     284
  63.    #define KEYBOARD_CATEGORY     4
  64.    #define KBD_GETSHIFTSTATE     0x0073
  65.    #define DATA_SIZE             3
  66.    BLObSize(Data,DATA_SIZE);
  67.    DynamicLink("doscalls",ORD_DOS32DEVIOCTL,BIT32,CDECL,
  68.                FileHandle,KEYBOARD_CATEGORY,KBD_GETSHIFTSTATE,
  69.                NULL,0,NULL,Data,DATA_SIZE,NULL);
  70.    ShiftState = BLObGet(Data,0,UWORD16);
  71.  
  72.    // call DosDevIOCTL to set kbd state
  73.    ShiftState |= NUMLOCK_BIT;
  74.    #define KBD_SETSHIFTSTATE     0x0053
  75.    BLObPut(Parms,ShiftState,UWORD16);
  76.    DynamicLink("doscalls",ORD_DOS32DEVIOCTL,BIT32,CDECL,
  77.                FileHandle,KEYBOARD_CATEGORY,KBD_SETSHIFTSTATE,
  78.                Parms,DATA_SIZE,NULL,NULL,0,NULL);
  79.  
  80.    // set LED's to show the state of the keyboard
  81.    #define KBD_SETLEDS  0x005A
  82.    leds = (ShiftState & 0x70) >> 4;
  83.    BLObPut(Parms,0,leds,UWORD16);
  84.    DynamicLink("doscalls",ORD_DOS32DEVIOCTL,BIT32,CDECL,
  85.                FileHandle,KEYBOARD_CATEGORY,KBD_SETLEDS,
  86.                Parms,2,NULL,NULL,0,NULL);
  87.  
  88.    // close device
  89.    #define ORD_DOS32CLOSE  257
  90.    DynamicLink("doscalls",ORD_DOS32CLOSE,BIT32,CDECL,FileHandle);
  91. }
  92.  
  93.  
  94. /*RESIDENT*/
  95. // All code below this is part of the resident program
  96.  
  97. WindowTitle = "NumLock Forever";
  98.  
  99. Forever(WaitInterval)
  100. {
  101.    // hide this window
  102.    system("WinSet \"%s\" HIDE",WindowTitle);
  103.    // check at every interval and set keyboard if it is not already set
  104.    for(;;) {
  105.       SetGlobalKeyboardTable();
  106.       suspend(WaitInterval);
  107.    }
  108. }
  109.  
  110. SetGlobalKeyboardTable() // set VK_NUMLOCK bit if not already set
  111. {
  112.    #define HWND_DESKTOP                     1
  113.    #define VK_NUMLOCK     0x1D
  114.    #define ORD_WIN32SETKEYBOARDSTATETABLE   921
  115.    KeyTable[255] = '\0'; // pre-allocate a 256 byte buffer
  116.    if ( DynamicLink("PMWIN",ORD_WIN32SETKEYBOARDSTATETABLE,BIT32,CDECL,
  117.                     HWND_DESKTOP,KeyTable,FALSE) ) {
  118.       if ( !(KeyTable[VK_NUMLOCK] & 1) ) {
  119.          KeyTable[VK_NUMLOCK] |= 1;
  120.          DynamicLink("PMWIN",ORD_WIN32SETKEYBOARDSTATETABLE,BIT32,CDECL,
  121.                      HWND_DESKTOP,KeyTable,TRUE);
  122.       }
  123.    }
  124. }
  125.  
  126.