1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

AHK v2で左右のaltキーをIMEの切り替えに割り当てる

Last updated at Posted at 2025-04-09

これを長年愛用していたが、最近になってaltが押されっぱなしのような挙動をするように

修正についで、AutoHotkey v2に対応するスクリプトへ書き直したものを以下に残す。

alt-ime.ahk
IME_SET(SetSts, WinTitle := "A") {
    hwnd := DllCall("FindWindow", "Str", WinTitle, "Ptr", 0, "Ptr")
    
    if (WinActive(WinTitle)) {
        ptrSize := !A_PtrSize ? 4 : A_PtrSize
        ; メモリ領域を確保するために GlobalAlloc を使用
        stGTI_cbSize := 4 + 4 + (ptrSize * 6) + 16
        stGTIBuffer := DllCall("GlobalAlloc", "UInt", 0x40, "UInt", stGTI_cbSize, "Ptr")  ; GMEM_FIXED = 0x40
        
        ; GlobalAllocで得たポインタにcbSizeを設定
        NumPut "UInt", stGTI_cbSize, stGTIBuffer, 0
        
        ; GUIThreadInfoを取得
        hwnd := DllCall("GetGUIThreadInfo", "UInt", 0, "UInt", stGTIBuffer)
            ? NumGet(stGTIBuffer, 8 + ptrSize, "UInt")
            : hwnd
    }

    ; IMEコントロールメッセージを送信
    DllCall("SendMessage"
          , "UInt", DllCall("imm32\ImmGetDefaultIMEWnd", "UInt", hwnd)
          , "UInt", 0x0283  ; Message : WM_IME_CONTROL
          , "Int", 0x006   ; wParam  : IMC_SETOPENSTATUS
          , "Int", SetSts)  ; lParam  : 0 or 1
}


~*LAlt::Send("{Blind}{vk07}")
~*RAlt::Send("{Blind}{vk07}")

LAlt Up::IME_SET(0)   ; LAltでIMEオフ
RAlt Up::IME_SET(1)   ; RAltでIMEオン
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?