In a Bas module
'API declarations
Declare Function GetKeyboardState Lib "user32" (pbKeyState As Byte) As Long
Declare Function SetKeyboardState Lib "user32" (lppbKeyState As Byte) As Long
Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
Function GetCapsLock() As Integer
'Returns the state of the CapsLock key
GetCapsLock = GetKeyState(vbKeyCapital)
End Function
Function GetNumLock() As Integer
'Returns the state of the NumLock key
GetNumLock = GetKeyState(vbKeyNumlock)
End Function
Function GetScrollLock() As Integer
'Returns the state of the ScrollLock key
GetScrollLock = GetKeyState(vbKeyScrollLock)
End Function
Sub SetCapsLock(Value As Boolean)
'Sets the state of the CapsLock key
Call SetKeyState(vbKeyCapital, Value)
End Sub
Sub SetNumLock(Value As Boolean)
'Sets the state of the NumLock key
Call SetKeyState(vbKeyNumlock, Value)
End Sub
Sub SetScrollLock(Value As Boolean)
'Sets the state of the ScrollLock key
Call SetKeyState(vbKeyScrollLock, Value)
End Sub
Private Sub SetKeyState(KeyName As Integer, KeyValue As Boolean)
'This code will retrieve the keyboard state, sets the particular
'key state passed to the 'KeyName' argument with the value passed
'to the 'KeyValue' argument, and then sets the entire keyboard
'state back to the state it was before with the new value of the
'key just changed
Dim Buffer(0 To 255) As Byte
GetKeyboardState Buffer(0)
Buffer(KeyName) = CByte(Abs(KeyValue))
SetKeyboardState Buffer(0)
End Sub
Then just call the desired procedure. Hope this helps.
If you choose to battle wits with the witless be prepared to lose.
![[cheers] [cheers] [cheers]](/data/assets/smilies/cheers.gif)