3
votes

I have an autohotkey script that I use only in conjunction with my Japanese input.

I only have one input language on my computer (Japanese), and I type in English by using the Alphanumeric setting (I'm not switching to English language, it's still technically a Japanese input method. But it's the Alphanumeric keyboard which has roman letters and is still a part of the Japanese language package on my computer). I toggle between Alphanumeric characters & Hiragana using the built-in hotkey Alt + `. Right now, my AHK script has a Suspend toggle which I activate with the combination Alt + 1.

I've tried changing the Suspend Toggle to Alt + grave, but if I do that, I can't toggle the script off. My computer changes input languages (as per the built-in hotkey), but does nothing to activate/deactivate the AHK script.

Right now, when I change languages, I have to do two hotkey combinations in a row (First Alt + grave, then Alt + 1). It's pretty redundant. I'd like for AHK to recognize which input method I'm using (Alphanumeric or Hiragana), and turn on or off based on that info. OR, if I could simply have the Alt + grave work to simultaneously toggle both the input & the state (active/unactive) of my AHK script.

For more--maybe unnecessary--details: When I have the hiragana keyboard on, pressing the "s" key outputs と, the Japanese "TO". Usually, Shift + s would still output と. I wrote my AHK script to change Shift + s to ど, or Japanese "DO".

As it is now, if I switch back to Alphanumeric characters and hit "s", I of course get "s" as desired. But if I tried to type a capital S, I still get a ど because the Shift + s is still mapped to that hiragana.

2

2 Answers

1
votes

If, as you said, your computer changes input languages (as per the built-in hotkey), you can try this to activate/deactivate the AHK script:

SetTimer, SuspendScript, 500

    RETURN   ; === end of auto-execute section ===

; Your hotkeys here:
; ...

    SuspendScript:
If (GetKeyboardLanguage(WinActive("A")) = 0x0409) ; English
    Suspend Off
else
    Suspend On
Return   

; https://autohotkey.com/board/topic/116538-detect-which-language-is-currently-on/#entry672236
GetKeyboardLanguage(_hWnd=0){
    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
}
0
votes

The simplest way to do this would be to use this hotkey in Autohotkey:

~!`::

The tilde makes the hotkey "transparent": it will act on the hotkey, then pass it on to Windows, so other programmes can act on it as well. So you can then use this one hotkey to both switch input and do the Autohotkey action.