
Originariamente inviato da
krossk2
ciao a tutti, mi chiedevo se era possibile attivare e/o disattivare il caps lock da codice. come potrei fare?
EDIT: ho risolto, posto il codice che ho usato se dovesse servire a qualcuno...
Imports System.Runtime.InteropServices
Public Class Form1
<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
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
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
SetCapsLockKey(True)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
SetCapsLockKey(False)
End Sub
End Class