Skip to content

Instantly share code, notes, and snippets.

@SolidAlloy
Created February 15, 2024 14:47
Show Gist options
  • Save SolidAlloy/48c50a0ef0b500555f0a0b59784b1929 to your computer and use it in GitHub Desktop.
Save SolidAlloy/48c50a0ef0b500555f0a0b59784b1929 to your computer and use it in GitHub Desktop.
AutoHotKey script that skips Japanese when cycling through keyboard layouts, has a separate key for switching to Japanese, and automatically switches to hiragana. For those who have more keyboard layouts other than English and Japanese, and use Japanese rarely.
#Requires AutoHotkey v2.0
; Makes Shift+Alt skip Japanese
~+Alt::
{
sleep(150)
if (GetKeyboardLanguage(WinExist("A")) = 1041) {
Send "{Shift Down}{Alt}{Shift Up}"
}
}
; Switches to Japanese, then switches to hiragana within Jap.
; I tried mapping Ctrl+Shift+Alt but it causes infinite loops.
; Ctrl+Shift works but only when Shift is pressed first. Maybe it's possible to implement but I gave up.
f2::
{
if (GetKeyboardLanguage(WinExist("A")) = 1041) {
Send "{Shift Down}{Alt}{Shift Up}"
}
else {
while (GetKeyboardLanguage(WinExist("A")) != 1041) {
Send "{Shift Down}{Alt}{Shift Up}"
sleep(150)
}
Send "^{CapsLock}"
}
}
return
GetKeyboardLanguage(_hWnd)
{
if !_hWnd
ThreadId :=0
else
if !ThreadId := DllCall("user32.dll\GetWindowThreadProcessId", "Ptr", _hWnd, "UInt", 0, "UInt")
return false
if !KBLayout := DllCall("user32.dll\GetKeyboardLayout", "UInt", ThreadId, "UInt")
return false
return KBLayout & 0xFFFF
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment