-
-
Save volks73/1e889e01ad0a736159a5d56268a300a8 to your computer and use it in GitHub Desktop.
| ; 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 |
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:)
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"
}
}@rhh4x0r thank you so much! I’ve been trying to find a working version for v2 for a while
@rhh4x0r LifeSaver man, it works perfectly!
Thanks @rhh4x0r!
maybe add following line at the beginning to disable capslock completely.
SetCapsLockState 'AlwaysOff'
My version for holding Ctrl and toggle Caps (ahk v2)
CapsLock::
{
Send "{Blind}{LControl down}"
}
CapsLock up::
{
Send "{Blind}{LControl Up}"
if (A_PriorKey == "CapsLock" and A_TimeSincePriorHotkey < 400)
{
SetCapsLockState !GetKeyState("CapsLock", "T")
}
}Thank you so much!! @rhh4x0r!
My version for holding Ctrl and toggle Caps (ahk v2)
CapsLock:: { Send "{Blind}{LControl down}" } CapsLock up:: { Send "{Blind}{LControl Up}" if (A_PriorKey == "CapsLock" and A_TimeSincePriorHotkey < 400) { SetCapsLockState !GetKeyState("CapsLock", "T") } }
That is for capslock and control not control and escape.
That is for capslock and control not control and escape.
yes, I said that in the first place 🫣
For some people like me, the above scripts may not work, because it seems that Caps Lock gets repeated when it is held, therefore the timer gets reset every 50 milliseconds or so. So I wrote this:
capsLockTime := 0
capsLockIsDown := false
*CapsLock::
{
global capsLockIsDown
global capsLockTime
Send "{Blind}{LControl down}"
if (!capsLockIsDown) {
capsLockTime := A_TickCount
capsLockIsDown := true
}
}
*CapsLock up::
{
global capsLockIsDown
if (capsLockIsDown) {
Send "{Blind}{LControl Up}"
global capsLockTime
if (A_TickCount - capsLockTime < 200) { ; modify time here
Suspend "1"
Send "{Esc}"
Suspend "0"
}
capsLockIsDown := false
}
}Maybe someone could make it shorter or something (I am new to AHK myself), but it works.
Thanks. After trying out a few other options. This seems to be working the most consistent.