0
votes

I have a simple AutoHotKey script:

Capslock::Ctrl
#Capslock::Capslock 

The point is, occasionally the capslock mode is activated even though I only want it to function as Ctrl, and I can't make it stop. The only way to do that is suspense the script, fix it, then reactivate it.

How can I make it works as intended?


Key history

VK  SC  Type    Up/Dn   Elapsed Key     Window
----------------------------------------------
14  03A h   d   0.03    CapsLock        
11  01D i   d   0.00    Control         
14  03A h   d   0.03    CapsLock        
11  01D i   d   0.00    Control         
14  03A h   d   0.03    CapsLock        
11  01D i   d   0.00    Control         
14  03A h   d   0.03    CapsLock        
11  01D i   d   0.00    Control         
14  03A h   d   0.03    CapsLock        
11  01D i   d   0.00    Control         
14  03A h   d   0.03    CapsLock        
11  01D i   d   0.00    Control         
14  03A h   d   0.03    CapsLock        
11  01D i   d   0.00    Control         
14  03A h   d   0.03    CapsLock        
11  01D i   d   0.00    Control         
14  03A h   d   0.03    CapsLock        
11  01D i   d   0.00    Control         
14  03A h   d   0.06    CapsLock        
14  03A h   d   0.03    CapsLock        
14  03A h   d   0.03    CapsLock        
11  01D i   d   0.03    Control         
11  01D i   d   0.00    Control         
14  03A h   d   0.00    CapsLock        
11  01D i   d   0.00    Control         
14  03A h   d   0.03    CapsLock        
11  01D i   d   0.00    Control         
14  03A h   u   0.03    CapsLock        
11  01D i   u   0.00    Control 
3
I tried it and I didn't get capslock to activate once except when pressing windowskey plus capslock as expected. But I did get warning when holding capslock for a couple of seconds about large number of hotkeys received in short period and to check #MaxHotkeysPerInterval. - Roman

3 Answers

1
votes

One noticeable problem with your code is that Ctrl is a modifier key while Capslock is not, which will produce unexpected results, including what Roman described.

Try this instead:

Capslock::SendInput {Ctrl Down}
Capslock Up::SendInput {Ctrl Up}
#Capslock::Capslock
1
votes

To answer:

Why does pressing Shift + Caps (Shift first) activate the capslock mode?

Because +Capslock is technically another hotkey you might want to assign another task to by adding another entry +Capslock:: and is therefore not captured by Capslock:: by default.

To capture all combinations without adding separate entries for each combination, try:

*Capslock::SendInput {Blind}{Ctrl Down}
*Capslock Up::SendInput {Blind}{Ctrl Up}

But then, this might interfere with the #Capslock:: entry depending on the context.

So, it's safe to specify all possible combos though it'd look a bit too complex and even ugly.

Edit:

Regarding the key history you added,

  1. Do you see 3 CapsLock entries followed by only 2 Control ones in the middle? I guess that's where the script somehow 'missed' the key press event, which happens when the script itself is too busy doing something else or the OS is not giving enough time slices to the script due to other tasks hogging the CPU.
  2. I've mapped an infrequently used key to modify and map I, ,, J and L to Up, Down, Left and Right, and sometimes the same thing happens, too. Like if I press and hold a combination for a while to, say, go up 100+ lines, it leaves an unexpected i in the middle. Not always, but sometimes.
  3. Nonetheless, using Process Priority,, A at the top of the script does help, making the glitch happen much less often.
0
votes

As said in the answer of johnlee, it can be because

the script itself is too busy doing something else or the OS is not giving enough time slices to the script due to other tasks hogging the CPU

so there is nothing else I can do. So my solution is

#Space::Capslock

Using Capslock::Ctrl is better than Capslock::SendInput {Blind}{Ctrl Down} because it doesn't activate Shift + Ctrl when Shift is pressed first.