2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

AutoHotkey を使って Windows Terminal 上の Emacs に C-SPC を送る

Last updated at Posted at 2023-04-14

Windows Terminal などのターミナルエミュレータはキー入力をアスキーコードとして受け取る。
その場合、1部の特殊キーは認識されない。

Emacs で良く利用するキー、コマンドとして C-SPC を使った set-mark-command があるが、
C-SPC が Windows Terminal 上では使えないため、Windows Terminal から ssh 接続した先で
Emacs を利用する際、set-mark-command が使えない。

一方で Emacs には event-apply-\*-modifiers という関数があり、後続のキーの前にモディファイアキーが押されているとしてキー入力を受け付けることができ、C-x @ [hsmaSc] に割当られている。
例えば C-x @ c SPC と入力すれば C-SPC に割当られたコマンドを呼び出すことができる。

そこで、AutoHotKey で Windows Terminal を利用しているときに C-SPC が押されたら、
C-x @ c SPC を送信するように設定する。

※ Sleep は気持ち。入れなくても動く。

    #IfWinActive, ahk_exe WindowsTerminal.exe
    {
    ^Space::
    {
        Send, ^x
        Sleep, 50
        Send, @
        Sleep, 50
        Send, c
        Sleep, 50
        Send, {Space}
        Return
    }
    }

V2 版

    #HotIf WinActive("ahk_exe WindowsTerminal.exe") {
      ^Space::
      {
        Send, ^x
        Sleep, 50
        Send, @
        Sleep, 50
        Send, c
        Sleep, 50
        Send, {Space}
        Return
      }
    }
2
0
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
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?