home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 24 / CDACTUAL24.iso / SHARE / os2 / edm2 / common / snippets / numlock2.txt < prev    next >
Encoding:
Internet Message Format  |  1997-01-25  |  3.0 KB

  1. From: neridan@central.co.nz (Neil Daniell)
  2.  
  3. Setting / Unsetting NumLock Status in OS/2 App
  4.  
  5. [1] Required variables:
  6.  
  7.         HFILE                hfile;              // File handle for device
  8.         ULONG                ulAction;
  9.         ULONG                ulLength;
  10.         BYTE                 KeyState[257];
  11.         SHIFTSTATE           strShiftState;
  12.         unsigned short       usLightState;
  13.  
  14.  
  15. [2] Open keyboard device for use with DosDevIOCtl:
  16.         DosOpen (
  17.                 "KBD$",
  18.                 &hfile,
  19.                 &ulAction,
  20.                 0L,
  21.                 0,
  22.                 FILE_OPEN,
  23.                 OPEN_ACCESS_READONLY | OPEN_SHARE_DENYNONE,
  24.                 0 );
  25.  
  26. [3] Obtain Shift Status information
  27.         using DosDevIOCtl         Category IOCTL_KEYBBOARD        ( 0x0004 )
  28.                                 Function KBD_GETSHIFTSTATE        ( 0x0073 )
  29.  
  30.         ulAction = 0;
  31.         ulLength = sizeof ( strShiftState );
  32.  
  33.         DosDevIOCtl (
  34.                 hfile,
  35.                 IOCTL_KEYBOARD,
  36.                 KBD_GETSHIFTSTATE,
  37.                 0,
  38.                 0,
  39.                 &ulAction,
  40.                 &strShiftState,
  41.                 sizeof( strShiftState ),
  42.                 &ulLength );
  43.  
  44. [4] Get Keyboard state table:
  45.  
  46.         WinSetKeyboardStateTable (
  47.                 HWND_DEKSTOP,
  48.                 &KeyState[1],
  49.                 FALSE );
  50.  
  51. [5] Set shift and key state:
  52.  
  53. If setting key ON:
  54.         KeyState[VK_NUMLOCK+1] |= 0x01;
  55.         strShiftState.fsState |= NUMLOCK_ON;
  56.  
  57. If setting key OFF:
  58.         KeyState[VK_NUMLOCK+1] &= ~0x01;
  59.         strShiftState.fsState &= ~NUMLOCK_ON;
  60.  
  61. [6] Update keyboard state table:
  62.  
  63.         WinSetKeyboardStateTable (
  64.                 HWND_DEKSTOP,
  65.                 &KeyState[1],
  66.                 TRUE );
  67.  
  68. [7] Update shift state:
  69.         using DosDevIOCtl         Category IOCTL_KEYBBOARD        ( 0x0004 )
  70.                                 Function KBD_SETSHIFTSTATE        ( 0x0053 )
  71.  
  72.         ulAction = sizeof ( strShiftState );
  73.         ulLength = 0;
  74.  
  75.         DosDevIOCtl (
  76.                 hfile,
  77.                 IOCTL_KEYBOARD,
  78.                 KBD_SETSHIFTSTATE,
  79.                 &strShiftState,
  80.                 sizeof( strShiftState ),
  81.                 &ulAction,
  82.                 0,
  83.                 0,
  84.                 &ulLength );
  85.  
  86. [8] Set LED status
  87.         using DosDevIOCtl
  88.                 Category IOCTL_KEYBBOARD        ( 0x0004 )
  89.            Function KBD_ALTERKEYBOARDLED        ( 0x005A )
  90.                         NB: This constant is NOT predefined,
  91.                             will require specific declaration.
  92.  
  93.         usLightState = ( strShifState.fsState & ( CAPSLOCK_ON | NUMLOCK_ON |
  94. SCROLLLOCK_ON ) ) >> 4;
  95.         ulAction = sizeof ( usLightState );
  96.  
  97.         DosDevIOCtl (
  98.                 hfile,
  99.                 IOCTL_KEYBOARD,
  100.                 KBD_ALTERKEYBOARDLED,
  101.                 &usLightState,
  102.                 sizeof( usLightState ),
  103.                 &ulAction,
  104.                 0,
  105.                 0,
  106.                 &ulLength );
  107.  
  108.  
  109. [9] Close device:
  110.  
  111.                 DosClose ( hfile );
  112.