Imports System.Runtime.InteropServices
<DllImport("user32.dll", CallingConvention:=CallingConvention.StdCall, CharSet:=CharSet.Unicode, EntryPoint:="keybd_event", ExactSpelling:=True, SetLastError:=True)> _
Private Shared Function keybd_event(ByVal bVk As Int32, ByVal bScan As Int32, _
ByVal dwFlags As Int32, ByVal dwExtraInfo As Int32) As Boolean
End Function
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Unicode)> _
Private Shared Function GetKeyState(ByVal nVirtKey As Integer) As Short
End Function
Private Sub SetCapsLockKey(ByVal newState As Boolean)
' if the current state must be changed
If CBool(GetKeyState(Keys.CapsLock)) <> newState Then
' programmatically press and release the CapsLock key
keybd_event(Keys.CapsLock, 0, 0, 0)
keybd_event(Keys.CapsLock, 0, &H2, 0)
End If
End Sub