forked from kshenoy/CapsUnlocked
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCapsUnlocked.ahk
43 lines (38 loc) · 1.4 KB
/
CapsUnlocked.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
;=======================================================================================================================
; CAPS-UNLOCKED
;=======================================================================================================================
; This is a complete solution to map the CapsLock key to Control and Escape without losing the ability to toggle CapsLock
;
; * Use CapsLock as Escape if it's the only key that is pressed and released within 300ms (configurable)
; * Use CapsLock as LControl when used in conjunction with some other key or if it's held longer than 300ms
; * Toggle CapsLock by pressing LControl+CapsLock
#InstallKeybdHook
SetCapsLockState, alwaysoff
StartTime := 0
*Capslock::
if (GetKeyState("LControl", "P")) {
KeyWait, CapsLock
SetCapsLockState, % (t:=!t) ? "On" : "Off"
return
}
Send {LControl Down}
State := (GetKeyState("Alt", "P") || GetKeyState("Shift", "P") || GetKeyState("LWin", "P") || GetKeyState("RWin", "P"))
if ( !State
&& (StartTime = 0)) {
StartTime := A_TickCount
}
KeyWait, CapsLock
Send {LControl Up}
IniRead, condEscape, %A_ScriptDir%\Settings.ini, CapsUnlocked, TapEscape, 1
if ( State
|| !condEscape) {
return
}
elapsedTime := A_TickCount - StartTime
IniRead, timeout, %A_ScriptDir%\Settings.ini, CapsUnlocked, Timeout, 300
if ( (A_PriorKey = "CapsLock")
&& (A_TickCount - StartTime < timeout)) {
Send {Esc}
}
StartTime := 0
return