windowskeyboard-shortcutsautohotkeykey-bindings

How to map CapsLock to Esc and Ctrl in Autohotkey?


How to remap Capslock key in a way that pressing and releasing it registers as Escape key but pressing and holding it registers as Ctrl key modifier?

I'm looking for a windows solution preferably using Autohotkey v2.


Solution

  • #Requires AutoHotkey v2.0
    
    ; Remap Capslock to Ctrl:
    Capslock::Ctrl  
    
    Capslock Up::{
        Send "{Ctrl Up}"
        If (A_PriorKey = "Capslock") ; if Capslock was pressed alone
            Send "{Esc}"
    }
    

    EDIT:

    or this:

    #Requires AutoHotkey v2.0
    
    *CapsLock::Send "{Blind}{Ctrl DownR}"
    
    *CapsLock Up::
    {
        Send "{Blind}{Ctrl up}"
        If (A_PriorKey = "CapsLock")
            Send "{Esc}"
    }
    

    *Wildcard: Fires the hotkey even if extra modifiers (in this case Ctrl) are being held down.

    DownR has an effect similar to physically pressing the key.

    The Blind mode

    avoids releasing the modifier keys (Alt, Ctrl, Shift, and Win) if they started out in the down position...

    Modifier keys are restored differently to allow a Send to turn off a hotkey's modifiers even if the user is still physically holding them down. ...