(続)macOS SierraでKarabinerの「EISUU to Escape(入力ソースが日本語以外の場合のみ)」を実現する
Deprecated
もっと良い方法を見つけましたので、こちらを利用して下さい。
以下、元記事です。
以前の記事で、HammerspoonとKarabiner-Elementsを使って、 擬似的にKarabinerの「EISUU to Escape(入力ソースが日本語以外の場合のみ)」(下図)を 実現する方法を紹介しました。
→macOS SierraでKarabinerの「EISUU to Escape(入力ソースが日本語以外の場合のみ)」を実現する - のどあめ
この度、Karabiner-ElementsのComplex Modificationsを使うことで、 Karabiner-Elementsのみで実現する方法を見つけたので紹介します。(しかもこちらのほうが安定する)
参考にしたページ
- TerminalやMacVimでEsc (or ^[)キーで日本語IMEを英数に切り替える(Karabiner-Elementsによる設定) - Qiita
- 今回の方法はほぼこちらの方のアイデアをそのまま利用しています。
実現方法
まずは、この機能を実現するComplex Modificationsを作成します。
.config/karabiner/assets/complex_modifications/EisuuToEscapeInTerminal.json
に以下のようなjsonファイルを配置します。
{ "title": "Terminal等で入力ソースが日本語以外の場合に英数をEscapeに変更する", "rules": [ { "description": "Terminal等で入力ソースが日本語以外の場合に英数をEscapeに変更する", "manipulators": [ { "type": "basic", "from": { "key_code": "japanese_eisuu", "modifiers": { "optional": [ "any" ] } }, "to": [ { "key_code": "japanese_eisuu"}, { "set_variable": {"name": "jp_input", "value": 0}} ], "conditions": [ { "type": "variable_if", "name": "jp_input", "value": 1 }, { "type": "frontmost_application_if", "bundle_identifiers": [ "^com\\.apple\\.Terminal$", "^org\\.vim\\.", "^com\\.googlecode\\.iterm2$" ] } ] }, { "type": "basic", "from": { "key_code": "japanese_eisuu", "modifiers": { "optional": [ "any" ] } }, "to": [ { "key_code": "escape"} ], "conditions": [ { "type": "variable_if", "name": "jp_input", "value": 0 }, { "type": "frontmost_application_if", "bundle_identifiers": [ "^com\\.apple\\.Terminal$", "^org\\.vim\\.", "^com\\.googlecode\\.iterm2$" ] } ] }, { "type": "basic", "from": { "key_code": "japanese_kana", "modifiers": { "optional": [ "any" ] } }, "to": [ { "key_code": "japanese_kana"}, { "set_variable": {"name": "jp", "value": 1}} ], "conditions": [ { "type": "frontmost_application_if", "bundle_identifiers": [ "^com\\.apple\\.Terminal$", "^org\\.vim\\.", "^com\\.googlecode\\.iterm2$" ] } ] } ] } ] }
次に、Karabiner-ElementsのPreferenceから、 「Complex Modifications」→「Add rule」→「Terminal等で入力ソースが日本語以外の場合に英数をEscapeに変更する」を有効にします。
以上で、擬似的に日本語入力でないときのみ英数キーがEscape変わります。
ザックリした仕組み
- 「かな」と「英数」で、変数
jp_input
に1, 0を代入します。 - 変数
jp_input
が0のときのみ「英数」を「Escape」に変更します。
これで、「EISUU to Escape(入力ソースが日本語以外の場合のみ)」が擬似的に実現できます。