Skip to content

Instantly share code, notes, and snippets.

@jumper047
Last active March 21, 2023 16:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jumper047/ae15b5e484bfe207d14387b6ff82c5f1 to your computer and use it in GitHub Desktop.
Save jumper047/ae15b5e484bfe207d14387b6ff82c5f1 to your computer and use it in GitHub Desktop.
AHK config
;Recommended, but not required:
SendMode Input
#NoEnv
#SingleInstance force
#Include <dual/dual>
dual := new Dual
#Include <dual/defaults>
#If true ; Override defaults.ahk. There will be "duplicate hotkey" errors otherwise.
;; BigCtrl-like.
*Space::
*Space UP::dual.combine("RCtrl", A_ThisHotkey)
;; Russian keys fix
*,::
StringReplace, KeytoSend, A_ThisHotkey, *
dual.combo(",")
if (current_is_ru() && !GetKeyState("RCtrl") && !GetKeyState("RAlt") && !GetKeyState("LAlt")) {
if (GetKeyState("Shift")) {
dual.SendInput("{Shift Down}{vkBC}{Shift Up}")
} Else {
dual.SendInput("{vkBC}")
}
} Else {
SendInput {Blind}{%KeyToSend%}
}
Return
*.::
StringReplace, KeytoSend, A_ThisHotkey, *
dual.combo(".")
if (current_is_ru() && !GetKeyState("RCtrl") && !GetKeyState("RAlt") && !GetKeyState("LAlt")) {
if (GetKeyState("Shift")) {
dual.SendInput("{Shift Down}{vkBE}{Shift Up}")
} Else {
dual.SendInput("{vkBE}")
}
} Else {
SendInput {Blind}{%KeyToSend%}
}
Return
*/::
StringReplace, KeytoSend, A_ThisHotkey, *
dual.combo("/")
if (current_is_ru() && !GetKeyState("RCtrl") && !GetKeyState("RAlt") && !GetKeyState("LAlt")) {
if (GetKeyState("Shift")) {
dual.SendInput("{Shift Down}{vkBF}{Shift Up}")
} Else {
dual.SendInput("{vkBF}")
}
} Else {
SendInput {Blind}{%KeyToSend%}
}
Return
*`;::
StringReplace, KeytoSend, A_ThisHotkey, *
dual.combo("`;")
if (current_is_ru() && !GetKeyState("RCtrl") && !GetKeyState("RAlt") && !GetKeyState("LAlt")) {
if (GetKeyState("Shift")) {
dual.SendInput("{Shift Down}{vkBA}{Shift Up}")
} Else {
dual.SendInput("{vkBA}")
}
} Else {
SendInput {Blind}{%KeyToSend%}
}
Return
*'::
StringReplace, KeytoSend, A_ThisHotkey, *
dual.combo("'")
if (current_is_ru() && !GetKeyState("RCtrl") && !GetKeyState("RAlt") && !GetKeyState("LAlt")) {
if (GetKeyState("Shift")) {
dual.SendInput("{Shift Down}{vkDE}{Shift Up}")
} Else {
dual.SendInput("{vkDE}")
}
} Else {
SendInput {Blind}{%KeyToSend%}
}
Return
;;Useless for me for now, may be add it late
;;*\::
*[::
StringReplace, KeytoSend, A_ThisHotkey, *
dual.combo("[")
if (current_is_ru() && !GetKeyState("RCtrl") && !GetKeyState("RAlt") && !GetKeyState("LAlt")) {
if (GetKeyState("Shift")) {
dual.SendInput("{Shift Down}{vkDB}{Shift Up}")
} Else {
dual.SendInput("{vkDB}")
}
} Else {
SendInput {Blind}{%KeyToSend%}
}
Return
*]::
StringReplace, KeytoSend, A_ThisHotkey, *
dual.combo("]")
if (current_is_ru() && !GetKeyState("RCtrl") && !GetKeyState("RAlt") && !GetKeyState("LAlt")) {
if (GetKeyState("Shift")) {
dual.SendInput("{Shift Down}{vkDD}{Shift Up}")
} Else {
dual.SendInput("{vkDD}")
}
} Else {
SendInput {Blind}{%KeyToSend%}
}
Return
#If
*ScrollLock::dual.reset()
; lang change on CAPS
Capslock:: ToggleInputLang()
; Some helper functions
; RU - 0x4190419
; EN - 0x4090409
current_layout()
{
SetFormat, Integer, H
WinGet, WinID,, A
ThreadID:=DllCall("GetWindowThreadProcessId", "UInt", WinID, "UInt", 0)
InputLocaleID:=DllCall("GetKeyboardLayout", "UInt", ThreadID, "UInt")
Return InputLocaleID
; if (InputLocaleID == "0x4190419") Return True
}
current_is_ru()
{
CurrLoc := current_layout()
if(CurrLoc = "0x4190419") {
return True
}
}
ToggleInputLang()
{
WinExist("A")
ControlGetFocus, CtrlInFocus
PostMessage, 0x50, 2,, %CtrlInFocus%
if (current_is_ru()) {
SetScrollLockState, On
} Else {
SetScrollLockState, Off
}
}
@sourcevault
Copy link

Hi, this script is really cool !

could you explain me these two lines ?

StringReplace, KeytoSend, A_ThisHotkey, *
dual.combo("[")

why use dual.combo when you have written all the plumbing just below it ?

What does StringReplace ... do in this case ?

I want to adapt your script for the French letters shown below, with a modifer (F14?) key :

ç é â ê î ô û à è ì ò ù ë ï ü

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