0
votes

I want to press Ctrl + Capslock which will toggle lock the Ctrl state.

For Example,

If I press Ctrl + Capslock, then if I keep clicking google search results on chrome, each result will open in a new background tab or if I wish to save a pdf file I will simply press s instead of Ctrl + s

If I wish to disable this behavior, or in other words, unlock the Ctrl key, I can press Ctrl + Capslock again.

In other words,

Ctrl+Capslock combo will make it such that the Ctrl key is always pressed down without me actually pressing it. Redo-ing the combo un-presses Ctrl again.

I have seen this achieved here but using the Ctrl key itself.

I've tried modifying that version, however it is not working

Hotkey, ^CapsLock, Lock
return

Lock:
GetKeyState, state, Control, T
if state = D
Send {Control Down}
else
Send {Control Up}
1

1 Answers

0
votes

The issue is the control toggling function runs while the user is still holding control, so the function will always see control as being in the down state. To solve this, I suggest storing the "control lock" toggle state in a variable and waiting for control to be physically released before performing the function. Put together it looks like this.

#SingleInstance, force
crlock = false

^CapsLock::
    KeyWait, control, u
    IfEqual, crlock, false
    {
        Send, {Control Down}
        crlock = true
    }
     else
    {
        Send, {Control Up}
        crlock = false
    }
Return