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 >
Wrap
Text File
|
1995-08-14
|
2KB
|
63 lines
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 (Read/write)
'
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)
#Else
Private Declare Sub GetKeyboardState Lib "user32" _
(lpKeyState As Any)
Private Declare Sub SetKeyboardState Lib "user32" _
(lpKeyState As Any)
#End If
' The index for the NumLock key in the 256-byte lpKeyState array.
Const VK_NUMLOCK = &H90
' 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