Ativando o Num Lock via código
1a. Parte:
Insira o seguinte código nas declrações gerais de um módulo .BAS
Public Const VK_NUMLOCK = &H90
Public Type KeyboardBytes
kbByte(0 To 255) As Byte
End Type
Public kbArray As KeyboardBytes
Public Declare Function GetKeyState Lib “user32” (ByVal nVirtKey
As Long) As Long
Public Declare Function GetKeyboardState Lib “user32” (kbArray As
KeyboardBytes) As Long
Public Declare Function SetKeyboardState Lib “user32” (kbArray As
KeyboardBytes) As Long
2a. Parte:
Crie um form e adicione 3 botões (cmdToggle, cmdTurnOn, cmdTurnOff) e um label.
Adicione o seguinte código no Form:
Private Sub cmdToggle_Click()
GetKeyboardState kbArray
kbArray.kbByte(VK_NUMLOCK) = IIf(kbArray.kbByte(VK_NUMLOCK) = 1, 0, 1)
SetKeyboardState kbArray
End Sub
Private Sub cmdTurnOn_Click()
GetKeyboardState kbArray
kbArray.kbByte(VK_NUMLOCK) = 1
SetKeyboardState kbArray
End Sub
Private Sub cmdTurnOff_Click()
GetKeyboardState kbArray
kbArray.kbByte(VK_NUMLOCK) = 0
SetKeyboardState kbArray
End Sub