CapsLock durumunu değiştirmek için kullanabileceğiniz aşağıdaki kodu kullanabilirsiniz.
Gerekli malzemeler:
1-UserForm : UserForm1
2-Label : Label1
3-CommandButton: cmdTurnOn
4-CommandButton: cmdTurnOff
5-ToggleButton: cmdToggle
6-TextBox: TextBox1
Option Explicit
Private kbArray As KeyboardBytes
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 Type KeyboardBytes
kbByte(0 To 255) As Byte
End Type
Private Const VK_CAPITAL = &H14
Function CapsLock() As Boolean
CapsLock = (GetKeyState(VK_CAPITAL) And 1 = 1)
End Function
Private Sub cmdToggle_Click()
GetKeyboardState kbArray
kbArray.kbByte(VK_CAPITAL) = _
IIf(kbArray.kbByte(VK_CAPITAL) = 1, 0, 1)
SetKeyboardState kbArray
If CapsLock() Then
Label1.Caption = "On"
Else
Label1.Caption = "Off"
End If
End Sub
Private Sub cmdTurnOn_Click()
GetKeyboardState kbArray
kbArray.kbByte(VK_CAPITAL) = 1
SetKeyboardState kbArray
If CapsLock() Then
Label1.Caption = "On"
Else
Label1.Caption = "Off"
End If
End Sub
Private Sub cmdTurnOff_Click()
GetKeyboardState kbArray
kbArray.kbByte(VK_CAPITAL) = 0
SetKeyboardState kbArray
If CapsLock() Then
Label1.Caption = "On"
Else
Label1.Caption = "Off"
End If
End Sub
Private Sub UserForm_Initialize()
If CapsLock() = 1 Then Label1 = "On" Else Label1 = "Off"
End Sub