'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.
Even though I prefer the API function as in Foada's example, there is also an old VB control available for this in your VS\Common\Tools\Controls folder, called KeySta32.Ocx which does the same.
keysta32.ocx should be in tools\controls directory under VB6 on your original installation disk, as long as you're not running the Learning Edition, which doesn't include it.
For your first question, foada's code just does it.
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first
'People who live in windowed environments shouldn't cast pointers.'
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.