Skip to content

Instantly share code, notes, and snippets.

@volks73
Created September 26, 2017 14:47
Show Gist options
  • Save volks73/1e889e01ad0a736159a5d56268a300a8 to your computer and use it in GitHub Desktop.
Save volks73/1e889e01ad0a736159a5d56268a300a8 to your computer and use it in GitHub Desktop.
AutoHotkey script to change Caps Lock to Control on hold and Escape on press and release
; Change Caps Lock to Control when held down; otherwise, Escape
;
; Originally based on the answer provided in
; [this](https://superuser.com/questions/581692/remap-caps-lock-in-windows-escape-and-control)
; StackExchange SuperUser question.
;
; A shortcut should be created for this script and placed in the Windows 10
; user's startup folder to automatically enable the feature on boot/startup.
; The user's startup folder can be found using the following steps:
;
; 1. Windows Key+R. The _Run_ dialog will appear.
; 2. Enter the following: `%appdata%\Microsoft\Windows\Start Menu\Programs\Startup`
; 3. Press Enter key. A file explorer dialog will appear.
;
; Obviously, [AutoHotkey](https://autohotkey.com/) must be installed for this to work.
*CapsLock::
Send {Blind}{Ctrl Down}
cDown := A_TickCount
Return
*CapsLock up::
If ((A_TickCount-cDown)<400) ; Modify press time as needed (milliseconds)
Send {Blind}{Ctrl Up}{Esc}
Else
Send {Blind}{Ctrl Up}
Return
@Chribzzz
Copy link

Thank you so much, ahk is so confusing to me! This is exactly what i needed for arrow up key/shift function on my pok3r keyboard:)

@rhh4x0r
Copy link

rhh4x0r commented Sep 11, 2023

Here's my revised version for AHK v2:

*CapsLock::
{
    Send "{LControl down}"
}

*CapsLock up::
{
    Send "{LControl Up}"

    if (A_PriorKey=="CapsLock"){
	if (A_TimeSincePriorHotkey < 1000)
		Suspend "1"
		Send "{Esc}"
		Suspend "0"
	}
}

@dakennguyen
Copy link

@rhh4x0r thank you so much! I’ve been trying to find a working version for v2 for a while

@churchilldu
Copy link

@rhh4x0r LifeSaver man, it works perfectly!

@david-alvarez-rosa
Copy link

Thanks @rhh4x0r!

@RayneScofield
Copy link

maybe add following line at the beginning to disable capslock completely.

SetCapsLockState 'AlwaysOff'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment