Const VK_CAPITAL = &H14
Const VK_NUMLOCK = &H90
Const VK_SCROLL = &H91
Const VK_USED = VK_SCROLL
Private Type KeyboardBytes
kbByte(0 To 255) As Byte
End Type
Private Type KeyboardBytes
kbByte(0 To 255) As Byte
End Type
Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Long
Private Declare Function GetKeyboardState Lib "user32" (kbArray As KeyboardBytes) As Long
Private Declare Function SetKeyboardState Lib "user32" (kbArray As KeyboardBytes) As Long
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Dim kbArray As KeyboardBytes, CapsLock As Boolean, kbOld As
Private Sub TurnOn(vkKey As Long)
'Get the keyboard state
GetKeyboardState kbArray
'Change a key
kbArray.kbByte(vkKey) = 1
'Set the keyboard state
SetKeyboardState kbArray
End Sub
Private Sub TurnOff(vkKey As Long)
'Get the keyboard state
GetKeyboardState kbArray
'change a key
kbArray.kbByte(vkKey) = 0
'set the keyboard state
SetKeyboardState kbArray
End Sub
Private Sub Form_Unload(Cancel As Integer)
'restore the old keyboard state
SetKeyboardState kbOld
End Sub