home *** CD-ROM | disk | FTP | other *** search
- VERSION 1.0 CLASS
- BEGIN
- MultiUse = -1 'True
- END
- Attribute VB_Name = "Keyboard"
- Attribute VB_Creatable = True
- Attribute VB_Exposed = True
- ' Keyboard class -- KEYBOARD.CLS
- '
- ' Property
- ' NumLock
- '
- Option Explicit
-
- ' Declare Windows API calls used to get and set keyboard states.
- #If Win16 Then
- Private Declare Sub GetKeyboardState Lib "User" (lpKeyState As Any)
- Private Declare Sub SetKeyboardState Lib "User" (lpKeyState As Any)
- ' The index for the NumLock key in the 256-byte lpKeyState array.
- Const VK_NUMLOCK = &H90
- #Else
- Private Declare Sub GetKeyboardState Lib "User32" (lpKeyState As Any)
- Private Declare Sub SetKeyboardState Lib "User32" (lpKeyState As Any)
- ' The index for the NumLock key in the 256-byte lpKeyState array.
- Const VK_NUMLOCK = &H90
- #End If
-
- ' Returns the state of the NumLock key: True = on, False = Off
- Property Get NumLock() As Boolean
- ' Create an array to hold key states (256 bytes = 128 integers)
- Dim lpbKeyState(128) As Integer
- ' Get key state settings.
- GetKeyboardState lpbKeyState(0)
- ' Check the VK_NUMLOCK element of the array.
- If (lpbKeyState(VK_NUMLOCK / 2)) Then
- NumLock = True
- Else
- NumLock = False
- End If
- End Property
-
- ' Changes the state of the NumLock key: True = on, False = off
- Property Let NumLock(bState As Boolean)
- ' Create an array to hold key states (256 bytes = 128 integers)
- Dim lpbKeyState(128) As Integer
- ' Get key state settings.
- GetKeyboardState lpbKeyState(0)
- ' If the current state is the same as the bState, then no change needed.
- If lpbKeyState(VK_NUMLOCK / 2) And bState Then Exit Property
- ' Otherwise, set the correct value in the array.
- If bState Then
- lpbKeyState(VK_NUMLOCK / 2) = 1
- Else
- lpbKeyState(VK_NUMLOCK / 2) = 0
- End If
- ' Set the keyboard state.
- SetKeyboardState lpbKeyState(0)
- End Property
-
-