Excel VBA Estudos - Saberexcel
Estas declarações API e procedimentos do Aplicativo Microsoft Excel VBA, ativa e desativas a teclas NUM LOOK e CAPSLOCK
Private Type KeyboardBytes
kbByte(0 To 255) As Byte
End Type
Dim kbArray As KeyboardBytes
Private Declare Function GetKeyState Lib "User32" (ByVal nVirtKey) As Long
Private Declare Function GetKeyboardState Lib "User32" (kbArray As KeyboardBytes) As Long
Private Declare Function SetKeyboardState Lib "User32" (kbArray As KeyboardBytes) As Long
Const VK_NUMLOCK = &H90
Sub CapsLockOn()
GetKeyboardState kbArray
kbArray.kbByte(VK_NUMLOCK) = 1
SetKeyboardState kbArray
End Sub
Sub CapsLockOff()
GetKeyboardState kbArray
kbArray.kbByte(VK_NUMLOCK) = 0
SetKeyboardState kbArray
End Sub
'.........................'
Declare Function GetKeyboardState Lib "user32" (pbKeyState As Byte) As Long
Declare Function SetKeyboardState Lib "user32" (lppbKeyState As Byte) As Long
Sub SetMyNumLock()
' NUMLOCK Ligado e CAPSLOCK desligado
Dim Res As Long
Dim KBState(0 To 255) As Byte
Res = GetKeyboardState(KBState(0))
KBState(&H90) = 1 ' num lock 1 = on, 0 = off
KBState(&H14) = 0 ' caps lock 1 = on, 0 = off
Res = SetKeyboardState(KBState(0))
End Sub
Aprenda tudo sobre o Aplicativo Microsoft Excel VBA com Saberexcel