Search code examples
autohotkeyremapctrlcapslock

autohotkey caps lock to ctrl not releasing


I'm using AutoHotkey to map the Caps Lock to Ctrl, and trying to use the Ctrl + K as Tab in Total Commander.

SetCapsLockState AlwaysOff
Capslock::Ctrl

#ifWinActive ahk_class TTOTAL_CMD
  ^k::Send, {Tab}
#ifWinActive

When i using the Ctrl + K remap with the normal Ctrl, it works fine. But when i trying to use it with the Caps Lock + K, then it works for the first time, but while i'm not releasing the Caps Lock, it sends k instead of Tab. The log says:

008: SetCapslockState,AlwaysOff
009: Return (3.49)
; Hiting Ctrl + K twice.
081: Send,{Tab} (0.02)
081: Return (0.30)
081: Send,{Tab} (0.02)
081: Return (1.59)
; Hiting Caps Lock + K twice.
009: SetKeyDelay,-1
009: Send,{Blind}{Ctrl DownTemp}
009: Return (0.47)
081: Send,{Tab} (0.01)
081: Return (0.73)
; The second Tab is missing, a simple K sent.
009: SetKeyDelay,-1
009: Send,{Blind}{Ctrl Up}
009: Return (3.06)

Here is the log, when i pressing Caps Lock + K, releasing it, then pressing againg:

009: SetKeyDelay,-1
009: Send,{Blind}{Ctrl DownTemp}
009: Return (0.34)
081: Send,{Tab} (0.01)
081: Return (0.08)
009: SetKeyDelay,-1
009: Send,{Blind}{Ctrl Up}
009: Return (0.34)
009: SetKeyDelay,-1
009: Send,{Blind}{Ctrl DownTemp}
009: Return (0.19)
081: Send,{Tab} (0.01)
081: Return (0.06)
009: SetKeyDelay,-1
009: Send,{Blind}{Ctrl Up}
009: Return (3.00)

I think the source of the problem may be in the CapsLock::Ctrl, but i didn't find any solution for it. Somebody meet with this problem?

EDIT:

Another interesting thing is when i sending code instead of a simple key, it works without releasing the caps lock:

^e::PostMessage, 1075, 3005, , , ahk_class TTOTAL_CMD ; cm_SwitchToNextTab=3005;Switch to next Tab (as Ctrl+Tab) (see TOTALCMD.INC file)

The log says:

008: SetCapslockState,AlwaysOff
009: Return (8.88)
; Ctrl + E twice.
058: PostMessage,1075,3005,,,ahk_class TTOTAL_CMD
058: Return (0.36)
058: PostMessage,1075,3005,,,ahk_class TTOTAL_CMD
058: Return (1.76)
009: SetKeyDelay,-1
; Caps Lock + E twice.
009: Send,{Blind}{Ctrl DownTemp}
009: Return (0.34)
058: PostMessage,1075,3005,,,ahk_class TTOTAL_CMD
058: Return (0.39)
058: PostMessage,1075,3005,,,ahk_class TTOTAL_CMD
058: Return (0.28)
009: SetKeyDelay,-1
009: Send,{Blind}{Ctrl Up}
009: Return (1.47)

; Caps Lock + E twice with releasing.
008: SetCapslockState,AlwaysOff
009: Return (2.54)
009: SetKeyDelay,-1
009: Send,{Blind}{Ctrl DownTemp}
009: Return (0.34)
058: PostMessage,1075,3005,,,ahk_class TTOTAL_CMD
058: Return (0.09)
009: SetKeyDelay,-1
009: Send,{Blind}{Ctrl Up}
009: Return (0.25)
009: SetKeyDelay,-1
009: Send,{Blind}{Ctrl DownTemp}
009: Return (0.23)
058: PostMessage,1075,3005,,,ahk_class TTOTAL_CMD
058: Return (0.08)
009: SetKeyDelay,-1
009: Send,{Blind}{Ctrl Up}
009: Return (1.98)

Solution

  • I remember running into odd issues like this when I was doing CapsLock remaps as well. Instead of mapping CapsLock to control and then using that combination in your hotkey, you could set CapsLock to do nothing but check the key's state in the #If directive. I would think this would resolve most of those odd issues.

    SetCapsLockState, AlwaysOff
    CapsLock::Return
    
    #If WinActive("ahk_class TTOTAL_CMD") and GetKeyState("CapsLock", "P")
        k::Send, {Tab}