Skip to content

Instantly share code, notes, and snippets.

@ulic-youthlic
Last active October 22, 2024 02:01
Show Gist options
  • Save ulic-youthlic/c8efd1d8cd5c59559403ded7e5b44833 to your computer and use it in GitHub Desktop.
Save ulic-youthlic/c8efd1d8cd5c59559403ded7e5b44833 to your computer and use it in GitHub Desktop.
map my <CapsLock> to <Esc>(alone) and <C-x>(with other key) using AutoHotKey v2.0.
#Requires AutoHotkey v2
; Install the keyboard hook to capture the real key state of the keyboard
InstallKeybdHook(true)
; Disable the CapsLock key
SetCapsLockState("alwaysoff")
; Send esc key when Capslock is pressed as default
g_DoNotAbortSendEsc := true
$*Capslock::{ ; Capture CapsLock key press
global g_DoNotAbortSendEsc ; use global variable g_DoNotAbortSendEsc
g_DoNotAbortSendEsc := true ; set g_DoNotAbortSendEsc to true
Send("{LControl Down}") ; send Ctrl key down
KeyWait("CapsLock") ; capture CapsLock key up
Send("{LControl Up}") ; send Ctrl key up
if (A_PriorKey == "CapsLock" ; if the last key is Capslock
&& g_DoNotAbortSendEsc) { ; if the g_DoNotAbortSendEsc is true
Send("{Esc}") ; send Esc key
}
return
}
; capture any key with Ctrl key down
~^*a:: ; * means can be used with any modifier key, ~ means donot block the original key, ^ means Ctrl key, a means the key is a
~^*b::
~^*c::
~^*d::
~^*e::
~^*f::
~^*g::
~^*h::
~^*i::
~^*j::
~^*k::
~^*l::
~^*m::
~^*n::
~^*o::
~^*p::
~^*q::
~^*r::
~^*s::
~^*t::
~^*u::
~^*v::
~^*w::
~^*x::
~^*y::
~^*z::
~^*1::
~^*2::
~^*3::
~^*4::
~^*5::
~^*6::
~^*7::
~^*8::
~^*9::
~^*0::
~^*Space::
~^*Backspace::
~^*Delete::
~^*Insert::
~^*Home::
~^*End::
~^*PgUp::
~^*PgDn::
~^*Tab::
~^*Enter::
~^*,::
~^*.::
~^*/::
~^*;::
~^*'::
~^*[::
~^*]::
~^*\::
~^*-::
~^*=::
~^*`::
~^*F1::
~^*F2::
~^*F3::
~^*F4::
~^*F5::
~^*F6::
~^*F7::
~^*F8::
~^*F9::
~^*F10::
~^*F11::
~^*F12::{
global g_DoNotAbortSendEsc
g_DoNotAbortSendEsc := false
}
@aabccd021
Copy link

How can I map ctrl+h to backspace, in addition to above script?

I ended up manually map caps lock pressed together with any key, to ctrl with the key

#Requires AutoHotkey v2

; Install the keyboard hook to capture the real key state of the keyboard
InstallKeybdHook(true)
; Disable the CapsLock key
SetCapsLockState("alwaysoff")

$*Capslock Up::{ 
  if (A_PriorKey == "CapsLock") {
    Send("{Esc}")
  }
}

Capslock & h:: Send '{Backspace}'
Capslock & m:: Send '{Enter}'

Capslock & a:: Send '^a'
Capslock & b:: Send '^b'
Capslock & c:: Send '^c'
Capslock & d:: Send '^d'
Capslock & e:: Send '^e'
Capslock & f:: Send '^f'
Capslock & g:: Send '^g'
Capslock & i:: Send '^i'
Capslock & j:: Send '^j'
Capslock & k:: Send '^k'
Capslock & l:: Send '^l'
Capslock & n:: Send '^n'
Capslock & o:: Send '^o'
Capslock & p:: Send '^p'
Capslock & q:: Send '^q'
Capslock & r:: Send '^r'
Capslock & s:: Send '^s'
Capslock & t:: Send '^t'
Capslock & u:: Send '^u'
Capslock & v:: Send '^v'
Capslock & w:: Send '^w'
Capslock & x:: Send '^x'
Capslock & y:: Send '^y'
Capslock & z:: Send '^z'
Capslock & 1:: Send '^1'
Capslock & 2:: Send '^2'
Capslock & 3:: Send '^3'
Capslock & 4:: Send '^4'
Capslock & 5:: Send '^5'
Capslock & 6:: Send '^6'
Capslock & 7:: Send '^7'
Capslock & 8:: Send '^8'
Capslock & 9:: Send '^9'
Capslock & 0:: Send '^0'
Capslock & Space:: Send '^Space'
Capslock & Backspace:: Send '^Backspace'
Capslock & Delete:: Send '^Delete'
Capslock & Insert:: Send '^Insert'
Capslock & Home:: Send '^Home'
Capslock & End:: Send '^End'
Capslock & PgUp:: Send '^PgUp'
Capslock & PgDn:: Send '^PgDn'
Capslock & Tab:: Send '^Tab'
Capslock & Enter:: Send '^Enter'
Capslock & ,:: Send '^,'
Capslock & .:: Send '^.'
Capslock & /:: Send '^/'
; Capslock & ;:: Send '^;'
Capslock & ':: Send "^'"
Capslock & [:: Send '^['
Capslock & ]:: Send '^]'
Capslock & \:: Send '^\'
Capslock & -:: Send '^-'
Capslock & =:: Send '^='
; Capslock & `:: Send '^`'
Capslock & F1:: Send '^F1'
Capslock & F2:: Send '^F2'
Capslock & F3:: Send '^F3'
Capslock & F4:: Send '^F4'
Capslock & F5:: Send '^F5'
Capslock & F6:: Send '^F6'
Capslock & F7:: Send '^F7'
Capslock & F8:: Send '^F8'
Capslock & F9:: Send '^F9'
Capslock & F10:: Send '^F10'
Capslock & F11:: Send '^F11'
Capslock & F12:: Send '^F12'

@ulic-youthlic
Copy link
Author

How can I map ctrl+h to backspace, in addition to above script?

I ended up manually map caps lock pressed together with any key, to ctrl with the key

#Requires AutoHotkey v2

; Install the keyboard hook to capture the real key state of the keyboard
InstallKeybdHook(true)
; Disable the CapsLock key
SetCapsLockState("alwaysoff")

$*Capslock Up::{ 
  if (A_PriorKey == "CapsLock") {
    Send("{Esc}")
  }
}

Capslock & h:: Send '{Backspace}'
Capslock & m:: Send '{Enter}'

Capslock & a:: Send '^a'
Capslock & b:: Send '^b'
Capslock & c:: Send '^c'
Capslock & d:: Send '^d'
Capslock & e:: Send '^e'
Capslock & f:: Send '^f'
Capslock & g:: Send '^g'
Capslock & i:: Send '^i'
Capslock & j:: Send '^j'
Capslock & k:: Send '^k'
Capslock & l:: Send '^l'
Capslock & n:: Send '^n'
Capslock & o:: Send '^o'
Capslock & p:: Send '^p'
Capslock & q:: Send '^q'
Capslock & r:: Send '^r'
Capslock & s:: Send '^s'
Capslock & t:: Send '^t'
Capslock & u:: Send '^u'
Capslock & v:: Send '^v'
Capslock & w:: Send '^w'
Capslock & x:: Send '^x'
Capslock & y:: Send '^y'
Capslock & z:: Send '^z'
Capslock & 1:: Send '^1'
Capslock & 2:: Send '^2'
Capslock & 3:: Send '^3'
Capslock & 4:: Send '^4'
Capslock & 5:: Send '^5'
Capslock & 6:: Send '^6'
Capslock & 7:: Send '^7'
Capslock & 8:: Send '^8'
Capslock & 9:: Send '^9'
Capslock & 0:: Send '^0'
Capslock & Space:: Send '^Space'
Capslock & Backspace:: Send '^Backspace'
Capslock & Delete:: Send '^Delete'
Capslock & Insert:: Send '^Insert'
Capslock & Home:: Send '^Home'
Capslock & End:: Send '^End'
Capslock & PgUp:: Send '^PgUp'
Capslock & PgDn:: Send '^PgDn'
Capslock & Tab:: Send '^Tab'
Capslock & Enter:: Send '^Enter'
Capslock & ,:: Send '^,'
Capslock & .:: Send '^.'
Capslock & /:: Send '^/'
; Capslock & ;:: Send '^;'
Capslock & ':: Send "^'"
Capslock & [:: Send '^['
Capslock & ]:: Send '^]'
Capslock & \:: Send '^\'
Capslock & -:: Send '^-'
Capslock & =:: Send '^='
; Capslock & `:: Send '^`'
Capslock & F1:: Send '^F1'
Capslock & F2:: Send '^F2'
Capslock & F3:: Send '^F3'
Capslock & F4:: Send '^F4'
Capslock & F5:: Send '^F5'
Capslock & F6:: Send '^F6'
Capslock & F7:: Send '^F7'
Capslock & F8:: Send '^F8'
Capslock & F9:: Send '^F9'
Capslock & F10:: Send '^F10'
Capslock & F11:: Send '^F11'
Capslock & F12:: Send '^F12'

If it's not too much trouble for you, give it a try kanata. this tool may be easier/elegant to do the same thing.

@ulic-youthlic
Copy link
Author

How can I map ctrl+h to backspace, in addition to above script?

I ended up manually map caps lock pressed together with any key, to ctrl with the key

#Requires AutoHotkey v2

; Install the keyboard hook to capture the real key state of the keyboard
InstallKeybdHook(true)
; Disable the CapsLock key
SetCapsLockState("alwaysoff")

$*Capslock Up::{ 
  if (A_PriorKey == "CapsLock") {
    Send("{Esc}")
  }
}

Capslock & h:: Send '{Backspace}'
Capslock & m:: Send '{Enter}'

Capslock & a:: Send '^a'
Capslock & b:: Send '^b'
Capslock & c:: Send '^c'
Capslock & d:: Send '^d'
Capslock & e:: Send '^e'
Capslock & f:: Send '^f'
Capslock & g:: Send '^g'
Capslock & i:: Send '^i'
Capslock & j:: Send '^j'
Capslock & k:: Send '^k'
Capslock & l:: Send '^l'
Capslock & n:: Send '^n'
Capslock & o:: Send '^o'
Capslock & p:: Send '^p'
Capslock & q:: Send '^q'
Capslock & r:: Send '^r'
Capslock & s:: Send '^s'
Capslock & t:: Send '^t'
Capslock & u:: Send '^u'
Capslock & v:: Send '^v'
Capslock & w:: Send '^w'
Capslock & x:: Send '^x'
Capslock & y:: Send '^y'
Capslock & z:: Send '^z'
Capslock & 1:: Send '^1'
Capslock & 2:: Send '^2'
Capslock & 3:: Send '^3'
Capslock & 4:: Send '^4'
Capslock & 5:: Send '^5'
Capslock & 6:: Send '^6'
Capslock & 7:: Send '^7'
Capslock & 8:: Send '^8'
Capslock & 9:: Send '^9'
Capslock & 0:: Send '^0'
Capslock & Space:: Send '^Space'
Capslock & Backspace:: Send '^Backspace'
Capslock & Delete:: Send '^Delete'
Capslock & Insert:: Send '^Insert'
Capslock & Home:: Send '^Home'
Capslock & End:: Send '^End'
Capslock & PgUp:: Send '^PgUp'
Capslock & PgDn:: Send '^PgDn'
Capslock & Tab:: Send '^Tab'
Capslock & Enter:: Send '^Enter'
Capslock & ,:: Send '^,'
Capslock & .:: Send '^.'
Capslock & /:: Send '^/'
; Capslock & ;:: Send '^;'
Capslock & ':: Send "^'"
Capslock & [:: Send '^['
Capslock & ]:: Send '^]'
Capslock & \:: Send '^\'
Capslock & -:: Send '^-'
Capslock & =:: Send '^='
; Capslock & `:: Send '^`'
Capslock & F1:: Send '^F1'
Capslock & F2:: Send '^F2'
Capslock & F3:: Send '^F3'
Capslock & F4:: Send '^F4'
Capslock & F5:: Send '^F5'
Capslock & F6:: Send '^F6'
Capslock & F7:: Send '^F7'
Capslock & F8:: Send '^F8'
Capslock & F9:: Send '^F9'
Capslock & F10:: Send '^F10'
Capslock & F11:: Send '^F11'
Capslock & F12:: Send '^F12'

If it's not too much trouble for you, give it a try kanata. this tool may be easier/elegant to do the same thing.

I'll give my kanata configuration as usual

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