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 / ch18code / keyboard.cls < prev    next >
Encoding:
Text File  |  1995-08-13  |  1.9 KB  |  60 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
  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" (lpKeyState As Any)
  18. Private Declare Sub SetKeyboardState Lib "User" (lpKeyState As Any)
  19. ' The index for the NumLock key in the 256-byte lpKeyState array.
  20. Const VK_NUMLOCK = &H90
  21. #Else
  22. Private Declare Sub GetKeyboardState Lib "User32" (lpKeyState As Any)
  23. Private Declare Sub SetKeyboardState Lib "User32" (lpKeyState As Any)
  24. ' The index for the NumLock key in the 256-byte lpKeyState array.
  25. Const VK_NUMLOCK = &H90
  26. #End If
  27.  
  28. ' Returns the state of the NumLock key: True = on, False = Off
  29. Property Get NumLock() As Boolean
  30.     ' Create an array to hold key states (256 bytes = 128 integers)
  31.     Dim lpbKeyState(128) As Integer
  32.     ' Get key state settings.
  33.     GetKeyboardState lpbKeyState(0)
  34.     ' Check the VK_NUMLOCK element of the array.
  35.     If (lpbKeyState(VK_NUMLOCK / 2)) Then
  36.         NumLock = True
  37.     Else
  38.         NumLock = False
  39.     End If
  40. End Property
  41.  
  42. ' Changes the state of the NumLock key: True = on, False = off
  43. Property Let NumLock(bState As Boolean)
  44.     ' Create an array to hold key states (256 bytes = 128 integers)
  45.     Dim lpbKeyState(128) As Integer
  46.     ' Get key state settings.
  47.     GetKeyboardState lpbKeyState(0)
  48.     ' If the current state is the same as the bState, then no change needed.
  49.     If lpbKeyState(VK_NUMLOCK / 2) And bState Then Exit Property
  50.     ' Otherwise, set the correct value in the array.
  51.     If bState Then
  52.         lpbKeyState(VK_NUMLOCK / 2) = 1
  53.     Else
  54.         lpbKeyState(VK_NUMLOCK / 2) = 0
  55.     End If
  56.     ' Set the keyboard state.
  57.     SetKeyboardState lpbKeyState(0)
  58. End Property
  59.  
  60.