Skip to content

Instantly share code, notes, and snippets.

@Menchen
Last active September 5, 2024 16:18
Show Gist options
  • Save Menchen/5f76d6837d33eeb1e31e46b1d08f21fb to your computer and use it in GitHub Desktop.
Save Menchen/5f76d6837d33eeb1e31e46b1d08f21fb to your computer and use it in GitHub Desktop.
AutoHotKey v2 script that simulate macOS's alt keys, only left alt are mapped, replace `<!` to `!` for both alt or `>!` for right alt
; this is a modification of the following Gist by Craig Patik: https://gist.github.com/patik/672d81b94195c418d855360529fe8008
; changes:
; - set tilde diacritic shortcut to "n" instead of "t"
; - update script to work with newer versions of AutoHotKey by replacing all instances of "VKC0SC029" by "sc029"
#UseHook
#Requires AutoHotkey v2.0
#SingleInstance Force
<!sc029::ActivateContext() ; grave -> the grave ` accent gave some probs, used the virtualkey + scancode instead
<!e::ActivateContext() ; acute
<!i::ActivateContext() ; circumflex
<!n::ActivateContext() ; tilde
<!u::ActivateContext() ; umlaut
ContextActive := false
; Define function to activate context
ActivateContext() {
global ContextActive
; Set context as active
ContextActive := true
; Set a timer to deactivate context after 2 seconds
SetTimer DeactivateContext, -2000
}
; Define function to deactivate context
DeactivateContext() {
; Reset context to inactive
global ContextActive
ContextActive := false
}
diacritic(regular,graveOption,graveShiftOption,acuteOption,acuteShiftOption,circumflexOption,circumflexShiftOption,tildeOption,tildeShiftOption,umlautOption,umlautShiftOption) {
;MsgBox A_PriorHotKey " " A_TimeSincePriorHotkey " " acuteOption
global ContextActive
ContextActive := false
if (A_PriorHotKey = "<!sc029" && A_TimeSincePriorHotkey < 2000) {
if (GetKeyState("Shift")) {
SendInput graveShiftOption
} else {
SendInput graveOption
}
} else if (A_PriorHotKey = "<!e" && A_TimeSincePriorHotkey < 2000) {
if (GetKeyState("Shift")) {
SendInput acuteShiftOption
} else {
SendInput acuteOption
}
} else if (A_PriorHotKey = "<!i" && A_TimeSincePriorHotkey < 2000) {
if (GetKeyState("Shift")) {
SendInput circumflexShiftOption
} else {
SendInput circumflexOption
}
} else if (A_PriorHotKey = "<!n" && A_TimeSincePriorHotkey < 2000) {
if (GetKeyState("Shift")) {
SendInput tildeShiftOption
} else {
SendInput tildeOption
}
} else if (A_PriorHotKey = "<!u" && A_TimeSincePriorHotkey < 2000) {
if (GetKeyState("Shift")) {
SendInput umlautShiftOption
} else {
SendInput umlautOption
}
} else {
if (GetKeyState("Shift") or GetKeyState("Capslock","T")) {
SendInput "+" regular
} else {
SendInput regular
}
}
}
#HotIf ContextActive
; 1 2 3 4 5 6 7 8 9 1
; 0
; r g G a A c C t T u U
*a::diacritic("a","à","À","á","Á","â","Â","ã","Ã","ä","Ä")
*e::diacritic("e","è","È","é","É","ê","Ê","e","E","ë","Ë")
*i::diacritic("i","ì","Ì","í","Í","î","Î","i","I","ï","Ï")
*o::diacritic("o","ò","Ò","ó","Ó","ô","Ô","õ","Õ","ö","Ö")
*u::diacritic("u","ù","Ù","ú","Ú","û","Û","u","U","ü","Ü")
*n::diacritic("n","n","N","n","N","n","N","ñ","Ñ","n","N")
*y::diacritic("y","y","Y","y","Y","y","Y","y","Y","ÿ","Ÿ")
#HotIf
;
; Alt + Shift + key
;
<!1::SendInput "¡"
<!+1::SendInput "/"
<!2::SendInput "€"
<!+2::SendInput "™"
<!3::SendInput "£"
<!+3::SendInput "‹"
<!4::SendInput "¢"
<!+4::SendInput "›"
<!5::SendInput "∞"
<!+5::SendInput "fi"
<!6::SendInput "§"
<!+6::SendInput "fl"
<!7::SendInput "¶"
<!+7::SendInput "‡"
<!8::SendInput "•"
<!+8::SendInput "°"
<!9::SendInput "ª"
<!+9::SendInput "·"
<!0::SendInput "º"
<!+0::SendInput "‚"
<!a::SendInput "å"
<!+a::SendInput "Å"
<!b::SendInput "∫"
<!+b::SendInput "ı"
<!c::SendInput "ç"
<!+c::SendInput "Ç"
<!d::SendInput "∂"
<!+d::SendInput "Î"
<!f::SendInput "ƒ"
<!+f::SendInput "Ï"
<!g::SendInput "©"
<!+g::SendInput "˝"
<!h::SendInput "˙"
<!+h::SendInput "Ó"
<!j::SendInput "∆"
<!+j::SendInput "Ô"
<!k::SendInput "˚"
<!+k::SendInput ""
<!l::SendInput "¬"
<!+l::SendInput "Ò"
<!m::SendInput "µ"
<!+m::SendInput "Â"
<!o::SendInput "ø"
<!+o::SendInput "Ø"
<!p::SendInput "π"
<!+p::SendInput "∏"
<!q::SendInput "œ"
<!+q::SendInput "Œ"
<!r::SendInput "®"
<!+r::SendInput "‰"
<!s::SendInput "ß"
<!+s::SendInput "Í"
<!t::SendInput "†"
<!+t::SendInput "ˇ"
<!v::SendInput "√"
<!+v::SendInput "◊"
<!w::SendInput "∑"
<!+w::SendInput "„"
<!x::SendInput "≈"
<!+x::SendInput "˛"
<!y::SendInput "¥"
<!+y::SendInput "Á"
<!z::SendInput "Ω"
<!+z::SendInput "¸"
<!-::SendInput "–"
<!+-::SendInput "—"
<!=::SendInput "≠"
<!+=::SendInput "±"
<![::SendInput "“"
<!+[::SendInput "”"
<!]::SendInput "‘"
<!+]::SendInput "’"
<!`;::SendInput "…"
<!+`;::SendInput "Ú"
<!'::SendInput "æ"
<!+'::SendInput "Æ"
<!\::SendInput "«"
<!+\::SendInput "»"
<!,::SendInput "≤"
<!+,::SendInput "¯"
<!.::SendInput "≥"
<!+.::SendInput "˘"
<!/::SendInput "÷"
<!+/::SendInput "¿"
<!+e::SendInput "´"
<!+i::SendInput "^"
<!+n::SendInput "˜"
<!+u::SendInput "¨"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment