macOS で CTRL と COMMAND-L を入れ替える備忘録

Apple
Photo by hyt.

macOS で CTRL と COMMAND-L を入れ替える備忘録です.

なぜ入れ替えるのか?

コピペを macOS でするのに多用する Command-L キーですが,正直場所が悪くて使いにくいです.ずっと我慢して使ってきたのですが,我慢しきれなくなり,Command-L キーと CTRL キーの役割を入れ替えることにしました.

ただし,何も考えずにそのまま入れ替えると,リモートデスクトップの Windows で同じ面倒が生じますし,ターミナル(私の場合は iTerm2)もそうです.と言うか,macOS と Windows で同じことするのに使うキーが違うと混乱します.だから,

  • リモートデスクトップと iTerm2 の場合は元のキー配置
  • 上記以外は CTRL と Command-L を入れ替え

入れ変えたい訳です.

もちろん,同じこと思っている人は当然たくさんいそうですし,実際,設定を紹介してくれている記事もググれば,

WindowsユーザーがMacOSでRemoteDesktop越しにWindowsを扱うときのキーマップ - Qiita
概要とかWindows育ちで109キーボードに慣れてるけど、スタバでMacbookAirでッターンとかしたいよね。的なアレでMacbookを持ち歩いてるんだけど、なんだかんだでWindows環境が…

のようにすぐ見つかりますが,情報が古いのか色々引っかかる部分があったので,私の場合の備忘録として記事にしたいと思います.

方法の詳細

ググった記事をみると大きく分けて方法は以下の2つのようです.

  • Karabina-Element を使う
  • Windows のレジストリを弄る

今回は iTerm2 もなんとかしないといけないので,Windows のレジストリを弄るのだと目的を達せませんので,フリーソフトの Karabina-Element を使う方法で行きます.

まず,やることは,Karabina-Element のインストールです.

次に,macOS の「システム環境設定」の「キーボード」のタブ,「キーボード」右下の「修飾キー」ボタンを押して現れる修飾キー役割の割り当てで CTRL と Command-L を以下の通り入れ替えます.

Photo by hyt.

次に,~/.config/karabiner/assets/complex_modifications/9999999999.json を以下の内容で作成します(これは Karabina-Element の Complex modification から参照できる設定集 https://ke-complex-modifications.pqrs.org にあった Remote Desktop 向けの設定の一部を書き換えたものです).

{
  "title": "Remote Desktop and iTerm2",
  "rules": [
    {
      "description": "Swap command and control for Remote Desktop and iTerm2",
      "manipulators": [
        {
          "type": "basic",
          "from": {
            "key_code": "left_control",
            "modifiers": {
              "optional": [
                "any"
              ]
            }
          },
          "to": [
            {
              "key_code": "left_command"
            }
          ],
          "conditions": [
            {
              "type": "frontmost_application_if",
              "bundle_identifiers": [
                "com\\.googlecode\\.iterm2",
                "com\\.microsoft\\.rdc\\.mac"
              ]
            }
          ]
        },
        {
          "type": "basic",
          "from": {
            "key_code": "left_command",
            "modifiers": {
              "optional": [
                "any"
              ]
            }
          },
          "to": [
            {
              "key_code": "left_control"
            }
          ],
          "conditions": [
            {
              "type": "frontmost_application_if",
              "bundle_identifiers": [
                "com\\.googlecode\\.iterm2",
                "com\\.microsoft\\.rdc\\.mac"
              ]
            }
          ]
        },
        {
          "type": "basic",
          "from": {
            "key_code": "right_control",
            "modifiers": {
              "optional": [
                "any"
              ]
            },
},
          "to": [
            {
              "key_code": "right_command"
            }
          ],
          "conditions": [
            {
              "type": "frontmost_application_if",
              "bundle_identifiers": [
                "com\\.googlecode\\.iterm2",
                "com\\.microsoft\\.rdc\\.mac"
              ]
            }
          ]
        },
        {
          "type": "basic",
          "from": {
            "key_code": "right_command",
            "modifiers": {
              "optional": [
                "any"
              ]
            }
          },
          "to": [
            {
              "key_code": "right_control"
            }
          ],
          "conditions": [
            {
              "type": "frontmost_application_if",
              "bundle_identifiers": [
                "com\\.googlecode\\.iterm2",
                "com\\.microsoft\\.rdc\\.mac"
              ]
            }
          ]
        }
      ]
    }
  ]
}

作成後,karabina-Element を起動し,「Complex modifications」タブを選択,+Add rule を選び,Swap command … を「Enable」すれば完了です.

Photo by hyt.

iTerm2 以外のアプリで同様の動作にしたい場合は,そのアプリ名(上の例だと,”com\\.googlecode\\.iterm2″ が iTerm2 の名前)を上のファイルの該当箇所に追加すれば良いだけです.アプリ名については Karabina-EventViewer アプリの「Frontmost application」タブを選び,該当のアプリを選択すれば表示されます.

以上!

 

AppleEnvironment
スポンサーリンク
Following hyt!
hyt adversaria
タイトルとURLをコピーしました