Programmatically disable caps lock

后端 未结 2 1726
有刺的猬
有刺的猬 2021-01-18 03:25

I\'m using SendKeys in an automation program for work. I\'ve been plodding along, and am now trying to iron out all the bugs that I\'ve created :-)

One of which, is

相关标签:
2条回答
  • 2021-01-18 03:36

    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
    
    0 讨论(0)
  • 2021-01-18 03:55

    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");
    
    0 讨论(0)
提交回复
热议问题