Option Explicit
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Declare Function SetKeyboardState Lib "user32" (lppbKeyState As Byte) As Long
Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
Private Declare Function MapVirtualKey Lib "user32" Alias "MapVirtualKeyA" (ByVal wCode As Long, ByVal wMapType As Long) As Long
Private Const VK_CAPITAL = &H14
Private Const KEYEVENTF_EXTENDEDKEY = &H1
Private Const KEYEVENTF_KEYUP = &H2
Public Sub SetKeyState(ByVal Key As Long, ByVal State As Boolean)
keybd_event Key, MapVirtualKey(Key, 0), KEYEVENTF_EXTENDEDKEY Or 0, 0
keybd_event Key, MapVirtualKey(Key, 0), KEYEVENTF_EXTENDEDKEY Or KEYEVENTF_KEYUP, 0
If Key = 20 And State = False Then
keybd_event 16, 0, 0, 0
keybd_event 16, 0, 2, 0
End If
End Sub
Public Property Get CapsLock() As Boolean
CapsLock = GetKeyState(VK_CAPITAL) = 1
End Property
Public Property Let CapsLock(ByVal Value As Boolean)
SetKeyState VK_CAPITAL, Value
End Property
|