Programmatically disable caps lock

做~自己de王妃 提交于 2019-12-01 17:38:01

does this work for you?

    if(Control.IsKeyLocked(Keys.CapsLock))
        SendKeys.SendWait("{CAPSLOCK}This Is An Over Capitalized Test String");
    else
        SendKeys.SendWait("This Is An Over Capitalized Test String");

I have an application, where I frequently need to switch between left-SHIFT and TAB. On my keyboard CAPSLOCK is between those 2 keys and I mistake now and then, typing a CAPSLOCK instead of a TAB. My solution is to reverse CAPSLOCK and submit a TAB instead. To my surprise the program loops until stack-overflow. I found out that the CAPSLOCK-key is send twice. This is my final solution:

Dim CapsLockProg As Integer = 0 ' after Send Capslock arrives 2 times!!!!!
Private Sub Description_KeyDown(sender As Object, e As KeyEventArgs) Handles Description.KeyDown 
    If e.KeyCode = Keys.Capital Then
        If CapsLockProg < 2 Then
            CapsLockProg += 1
            If CapsLockProg = 1 Then
                Windows.Forms.SendKeys.SendWait("{TAB}{CAPSLOCK}")
            'Else
            '   ignore 2nd Capslock
            End If 
        Else
            CapsLockProg = 0
        End If
    End If
    If e.KeyCode = Keys.Tab Then 
    rest of code
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!