Skip to content

Instantly share code, notes, and snippets.

@amirrajan
Forked from JustinJohnWilliams/esctrl.ahk
Created October 30, 2020 12:36
Show Gist options
  • Save amirrajan/9804b214dab9fe872d31f778db894fff to your computer and use it in GitHub Desktop.
Save amirrajan/9804b214dab9fe872d31f778db894fff to your computer and use it in GitHub Desktop.
esc ctrl remaps
g_LastCtrlKeyDownTime := 0
g_AbortSendEsc := false
g_ControlRepeatDetected := false
*CapsLock::
if (g_ControlRepeatDetected)
{
return
}
send,{Ctrl down}
g_LastCtrlKeyDownTime := A_TickCount
g_AbortSendEsc := false
g_ControlRepeatDetected := true
return
*CapsLock Up::
send,{Ctrl up}
g_ControlRepeatDetected := false
if (g_AbortSendEsc)
{
return
}
current_time := A_TickCount
time_elapsed := current_time - g_LastCtrlKeyDownTime
if (time_elapsed <= 250)
{
SendInput {Esc}
}
return
~*^a::
g_AbortSendEsc := true
return
~*^b::
g_AbortSendEsc := true
return
~*^c::
g_AbortSendEsc := true
return
~*^d::
g_AbortSendEsc := true
return
~*^e::
g_AbortSendEsc := true
return
~*^f::
g_AbortSendEsc := true
return
~*^g::
g_AbortSendEsc := true
return
~*^h::
g_AbortSendEsc := true
return
~*^i::
g_AbortSendEsc := true
return
~*^j::
g_AbortSendEsc := true
return
~*^k::
g_AbortSendEsc := true
return
~*^l::
g_AbortSendEsc := true
return
~*^m::
g_AbortSendEsc := true
return
~*^n::
g_AbortSendEsc := true
return
~*^o::
g_AbortSendEsc := true
return
~*^p::
g_AbortSendEsc := true
return
~*^q::
g_AbortSendEsc := true
return
~*^r::
g_AbortSendEsc := true
return
~*^s::
g_AbortSendEsc := true
return
~*^t::
g_AbortSendEsc := true
return
~*^u::
g_AbortSendEsc := true
return
~*^v::
g_AbortSendEsc := true
return
~*^w::
g_AbortSendEsc := true
return
~*^x::
g_AbortSendEsc := true
return
~*^y::
g_AbortSendEsc := true
return
~*^z::
g_AbortSendEsc := true
return
~*^1::
g_AbortSendEsc := true
return
~*^2::
g_AbortSendEsc := true
return
~*^3::
g_AbortSendEsc := true
return
~*^4::
g_AbortSendEsc := true
return
~*^5::
g_AbortSendEsc := true
return
~*^6::
g_AbortSendEsc := true
return
~*^7::
g_AbortSendEsc := true
return
~*^8::
g_AbortSendEsc := true
return
~*^9::
g_AbortSendEsc := true
return
~*^0::
g_AbortSendEsc := true
return
~*^Space::
g_AbortSendEsc := true
return
~*^Backspace::
g_AbortSendEsc := true
return
~*^Delete::
g_AbortSendEsc := true
return
~*^Insert::
g_AbortSendEsc := true
return
~*^Home::
g_AbortSendEsc := true
return
~*^End::
g_AbortSendEsc := true
return
~*^PgUp::
g_AbortSendEsc := true
return
~*^PgDn::
g_AbortSendEsc := true
return
~*^Tab::
g_AbortSendEsc := true
return
~*^Return::
g_AbortSendEsc := true
return
~*^,::
g_AbortSendEsc := true
return
~*^.::
g_AbortSendEsc := true
return
~*^/::
g_AbortSendEsc := true
return
~*^;::
g_AbortSendEsc := true
return
~*^'::
g_AbortSendEsc := true
return
~*^[::
g_AbortSendEsc := true
return
~*^]::
g_AbortSendEsc := true
return
~*^\::
g_AbortSendEsc := true
return
~*^-::
g_AbortSendEsc := true
return
~*^=::
g_AbortSendEsc := true
return
~*^`::
g_AbortSendEsc := true
return
~*^F1::
g_AbortSendEsc := true
return
~*^F2::
g_AbortSendEsc := true
return
~*^F3::
g_AbortSendEsc := true
return
~*^F4::
g_AbortSendEsc := true
return
~*^F5::
g_AbortSendEsc := true
return
~*^F6::
g_AbortSendEsc := true
return
~*^F7::
g_AbortSendEsc := true
return
~*^F8::
g_AbortSendEsc := true
return
~*^F9::
g_AbortSendEsc := true
return
~*^F10::
g_AbortSendEsc := true
return
~*^F11::
g_AbortSendEsc := true
return
~*^F12::
g_AbortSendEsc := true
return
$~*LShift::
;msgbox, %A_ThisHotkey% is down
;// when you hold down the key, this hotkey fires constnatly due to the normal OS-level repeat
;// so we only want to store the time from the initial downpress, not each OS-repeat)
;// and then during the 'up' hotkey, we reset this timestamp back to 0
if (!LShift_down_timestamp)
LShift_down_timestamp := A_TickCount
;// if any other modifiers are down along with this key, then we will not send the replacement key (left parens)
if (!LShift_modifiers_are_pressed)
LShift_modifiers_are_pressed := (GetKeyState("Control", "P") || GetKeyState("Alt", "P") || GetKeyState("LWin", "P") || GetKeyState("RWin", "P"))
return
$~LShift up::
;msgbox, %A_PriorKey%
;msgbox, %A_ThisHotkey%
;// check if EITHER shift key was the last key pressed
;// this allows accidental 'rolling': presing Lshift then Rshift very fast, where you hadn't fully released the LShift before RShift went down
;// also, you must press and release LShift within 300ms, otherwise this doesn't trigger.
;// i found myself sometimes holding LShift for a while, planning on capitalizing a letter
;// but then releasing the key, causing this hotkey to trigger erroneously
if (A_PriorKey ~= "LShift|RShift") && (!LShift_modifiers_are_pressed) && (A_TickCount - LShift_down_timestamp < 300)
Send, {Shift Down}9{Shift Up} ;// send left parenthesis
LShift_modifiers_are_pressed := false
LShift_down_timestamp := 0
return
$~*RShift::
;msgbox, %A_ThisHotkey% is down
;// when you hold down the key, this hotkey fires constnatly due to the normal OS-level repeat
;// so we only want to store the time from the initial downpress, not each OS-repeat)
;// and then during the 'up' hotkey, we reset this timestamp back to 0
if (!RShift_down_timestamp)
RShift_down_timestamp := A_TickCount
;// if any other modifiers are down along with this key, then we will not send the replacement key (left parens)
if (!RShift_modifiers_are_pressed)
RShift_modifiers_are_pressed := (GetKeyState("Control", "P") || GetKeyState("Alt", "P") || GetKeyState("LWin", "P") || GetKeyState("RWin", "P"))
return
$~RShift up::
;msgbox, %A_PriorKey%
;msgbox, %A_ThisHotkey%
;// check if EITHER shift key was the last key pressed
;// this allows accidental 'rolling': presing Lshift then Rshift very fast, where you hadn't fully released the RShift before RShift went down
;// also, you must press and release RShift within 300ms, otherwise this doesn't trigger.
;// i found myself sometimes holding RShift for a while, planning on capitalizing a letter
;// but then releasing the key, causing this hotkey to trigger erroneously
if (A_PriorKey ~= "RShift|RShift") && (!RShift_modifiers_are_pressed) && (A_TickCount - RShift_down_timestamp < 300)
Send, {Shift Down}0{Shift Up} ;// send left parenthesis
RShift_modifiers_are_pressed := false
RShift_down_timestamp := 0
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment