【Mac】Karabiner-Elementsでキー入力をカスタマイズ

スポンサーリンク

macOSでは、カーソル移動は Ctrl+p, Ctrl+n などを使うアプリが多いが、一部対応していないソフトでは不自由な時があるので「Karabiner-Elements」ソフトを使って、キー入力をカスタマイズしたので備忘録を残す。

Karabiner-Elements のインストール

GitHubの「Karabiner-Elements」のページにダウンロードサイトへの下記リンクが記載してあるので、そのインストーラをダウンロードし実行。

Karabiner-Elements
A powerful and stable keyboard customizer for macOS.

Karabiner-Elements の設定

Ctrl+p,Ctrl+n,Ctrl+m キー入力を、↑,↓,Enter キーに変更する。

~/.config/karabiner/karabiner.json ファイルを下記のように修正。("rules": [] あたりを変更追加)

{
    "global": {
        "check_for_updates_on_startup": true,
        "show_in_menu_bar": true,
        "show_profile_name_in_menu_bar": false
    },
    "profiles": [
        {
            "complex_modifications": {
                "parameters": {
                    "basic.simultaneous_threshold_milliseconds": 50,
                    "basic.to_delayed_action_delay_milliseconds": 500,
                    "basic.to_if_alone_timeout_milliseconds": 1000,
                    "basic.to_if_held_down_threshold_milliseconds": 500,
                    "mouse_motion_to_scroll.speed": 100
                },
                "rules": [
                    {
                        "description": "Change ctr+npm to arrow keys",
                        "manipulators": [
                            {
                                "from": {
                                    "key_code": "n",
                                    "modifiers": {
                                        "mandatory": [
                                            "left_control"
                                        ],
                                        "optional": [
                                            "any"
                                        ]
                                    }
                                },
                                "to": [
                                    {
                                        "key_code": "down_arrow"
                                    }
                                ],
                                "type": "basic"
                            },
                            {
                                "from": {
                                    "key_code": "p",
                                    "modifiers": {
                                        "mandatory": [
                                            "left_control"
                                        ],
                                        "optional": [
                                            "any"
                                        ]
                                    }
                                },
                                "to": [
                                    {
                                        "key_code": "up_arrow"
                                    }
                                ],
                                "type": "basic"
                            },
                            {
                                "from": {
                                    "key_code": "m",
                                    "modifiers": {
                                        "mandatory": [
                                            "left_control"
                                        ],
                                        "optional": [
                                            "any"
                                        ]
                                    }
                                },
                                "to": [
                                    {
                                        "key_code": "return_or_enter"
                                    }
                                ],
                                "type": "basic"
                            }
                        ]
                    }
                ]
            },
            "devices": [],
            "fn_function_keys": [
                {
                    "from": {
                        "key_code": "f1"
                    },
                    "to": {
                        "consumer_key_code": "display_brightness_decrement"
                    }
                },
                {
                    "from": {
                        "key_code": "f2"
                    },
                    "to": {
                        "consumer_key_code": "display_brightness_increment"
                    }
                },
                {
                    "from": {
                        "key_code": "f3"
                    },
                    "to": {
                        "key_code": "mission_control"
                    }
                },
                {
                    "from": {
                        "key_code": "f4"
                    },
                    "to": {
                        "key_code": "launchpad"
                    }
                },
                {
                    "from": {
                        "key_code": "f5"
                    },
                    "to": {
                        "key_code": "illumination_decrement"
                    }
                },
                {
                    "from": {
                        "key_code": "f6"
                    },
                    "to": {
                        "key_code": "illumination_increment"
                    }
                },
                {
                    "from": {
                        "key_code": "f7"
                    },
                    "to": {
                        "consumer_key_code": "rewind"
                    }
                },
                {
                    "from": {
                        "key_code": "f8"
                    },
                    "to": {
                        "consumer_key_code": "play_or_pause"
                    }
                },
                {
                    "from": {
                        "key_code": "f9"
                    },
                    "to": {
                        "consumer_key_code": "fastforward"
                    }
                },
                {
                    "from": {
                        "key_code": "f10"
                    },
                    "to": {
                        "consumer_key_code": "mute"
                    }
                },
                {
                    "from": {
                        "key_code": "f11"
                    },
                    "to": {
                        "consumer_key_code": "volume_decrement"
                    }
                },
                {
                    "from": {
                        "key_code": "f12"
                    },
                    "to": {
                        "consumer_key_code": "volume_increment"
                    }
                }
            ],
            "name": "Default profile",
            "selected": true,
            "simple_modifications": [],
            "virtual_hid_keyboard": {
                "country_code": 0
            }
        }
    ]
}

設定確認

Preferences... で定義が追加された事を確認。

画像01

CtrlとCapsキーを入れ替える

Windows用キーボードを接続した場合に、CtrlとCapsキーを入れ替えるには、下のように「Simple Modifications」で設定する。

画像10

尚、キーボードデバイス単位で設定が可能。

補足

  • key_codeは、同時にインストールされている「Karabiner-EventViewer」アプリケーションで調べる事ができる。
  • OSXの標準キーバインドは、~/Library/KeyBindings/DefaultKeyBinding.dict に記述する事でも変更できる。

関連記事

【Mac】macOS SierraでWindows用キーボードを使う(Karabiner-Elementsインストール)
macOSでWidowsキーボードを使うと、特に漢字入力に困る。以前は「Karrainer」というソフトを使っていたのだが、「macOS Sierra」にアップデートで動かなくなった。 「Karrabiner-Elements」を使う事で「...

参考

  1. macOS カーソル強制バインディングのすすめ
  2. DefaultKeyBinding.dictを使って、macOSのキーバインドを変更
  3. テキスト編集のキー操作を自在にコントロールする

コメント

タイトルとURLをコピーしました