home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Programmer'…arterly (Limited Edition) / Visual_Basic_Programmers_Journal_VB-CD_Quarterly_Limited_Edition_1995.iso / code / ch21code / keyboard.cls < prev    next >
Text File  |  1995-08-14  |  2KB  |  63 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "Keyboard"
  6. Attribute VB_Creatable = True
  7. Attribute VB_Exposed = True
  8. ' Keyboard class -- KEYBOARD.CLS
  9. '
  10. '   Property
  11. '       NumLock (Read/write)
  12. '
  13. Option Explicit
  14.  
  15. ' Declare Windows API calls used to get and set keyboard states.
  16. #If Win16 Then
  17. Private Declare Sub GetKeyboardState Lib "User" _
  18.     (lpKeyState As Any)
  19. Private Declare Sub SetKeyboardState Lib "User" _
  20.     (lpKeyState As Any)
  21. #Else
  22. Private Declare Sub GetKeyboardState Lib "user32" _
  23.     (lpKeyState As Any)
  24. Private Declare Sub SetKeyboardState Lib "user32" _
  25.     (lpKeyState As Any)
  26. #End If
  27.  
  28. ' The index for the NumLock key in the 256-byte lpKeyState array.
  29. Const VK_NUMLOCK = &H90
  30.  
  31. ' Returns the state of the NumLock key: True = on, False = Off
  32. Property Get NumLock() As Boolean
  33.     ' Create an array to hold key states (256 bytes = 128 integers)
  34.     Dim lpbKeyState(128) As Integer
  35.     ' Get key state settings.
  36.     GetKeyboardState lpbKeyState(0)
  37.     ' Check the VK_NUMLOCK element of the array.
  38.     If (lpbKeyState(VK_NUMLOCK / 2)) Then
  39.         NumLock = True
  40.     Else
  41.         NumLock = False
  42.     End If
  43. End Property
  44.  
  45. ' Changes the state of the NumLock key: True = on, False = off
  46. Property Let NumLock(bState As Boolean)
  47.     ' Create an array to hold key states (256 bytes = 128 integers)
  48.     Dim lpbKeyState(128) As Integer
  49.     ' Get key state settings.
  50.     GetKeyboardState lpbKeyState(0)
  51.     ' If the current state is the same as the bState, then no change needed.
  52.     If lpbKeyState(VK_NUMLOCK / 2) And bState Then Exit Property
  53.     ' Otherwise, set the correct value in the array.
  54.     If bState Then
  55.         lpbKeyState(VK_NUMLOCK / 2) = 1
  56.     Else
  57.         lpbKeyState(VK_NUMLOCK / 2) = 0
  58.     End If
  59.     ' Set the keyboard state.
  60.     SetKeyboardState lpbKeyState(0)
  61. End Property
  62.  
  63.