1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| 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_NUMLOCK = &H90
Private Const VK_SCROLL = &H91
Private Const VK_CAPITAL = &H14
Private Const VK_PAUSE = &H13
Private Const KEYEVENTF_EXTENDEDKEY = &H1
Private Const KEYEVENTF_KEYUP = &H2
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
Public Property Get NumLock() As Boolean
NumLock = GetKeyState(VK_NUMLOCK) = 1
End Property
Public Property Let NumLock(ByVal Value As Boolean)
SetKeyState VK_NUMLOCK, Value
End Property
Public Property Get ScrollLock() As Boolean
ScrollLock = GetKeyState(VK_SCROLL) = 1
End Property
Public Property Let ScrollLock(ByVal Value As Boolean)
SetKeyState VK_SCROLL, Value
End Property
Public Property Get PauseLock() As Boolean
PauseLock = GetKeyState(VK_PAUSE) = 1
End Property
Public Property Let PauseLock(ByVal Value As Boolean)
SetKeyState VK_PAUSE, Value
End Property
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 |
Partager