HHKB & Windows使いがKarabiner-Elementsの設定をしてみた

2021.02.03

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

こんにちは!DA(データアナリティクス)事業本部 インテグレーション部の大高です。

私は普段「Macbook Pro」を利用しているのですが、実はほとんどの開発作業は「VMWare Fusion上のWindows 10」で実施していました。一方で、最近はM1 Macが出てきたり、VMのWindowsの調子がいまいち良くなかったりすることもあり、いい加減Windowsから出てこようと一念発起をして環境整備をしています。

改めて考えると、私がMacを利用する上でのハードルとしては、「キーボードのショートカットが変わるのが辛い」というのがありました。特に長年利用している「Ctrl+c」、「Ctrl+v」などの「Ctrl」を利用するショートカットです。

これについて「Karabiner-Elements」というアプリを利用すれば解決できそうというのがわかったので、脱Windowsをするべく色々設定をしてみました。

前提

私の環境は以下になります。

キーボードはHHKBを利用しており、普段はクラムシェルモードでこちらだけを利用しています。また、DIPの設定は以下に設定しています。

SW1 SW2 MODE
OFF ON Macintosh


SW ON/OFF MODE
SW3 ON Delete='BS'
SW4 ON Left◇='Fn'
SW5 OFF ◇='◇',Alt='Alt'
SW6 OFF Wake Up Disable

ONにしていて設定に関係ありそうなのは、SW4の設定です。当エントリについてはこの設定を前提としています。

また、開発時には主に以下を利用しているので、このあたりをうまく動かしたいです。

  • Chrome
  • Visual Studio Code
  • VM(Windows 10)

Windows 10はあまり使わなくする想定ですが、環境としては残しておき、必要に応じていままで通りの操作をできるようにしたいと考えています。

では、この前提で始めていきます。

Karabiner-Elementsのインストール

こちらは公式サイトからダウンロードしてインストールするだけです。

Karabiner-Elementsの設定

設定ファイルとして下記のkarabiner-conf.jsonというファイルを作成し、~/.config/karabiner/assets/complex_modifications/karabiner-conf.jsonに配置しました。

配置後に、Karabiner-Elementsの設定画面を開き、「Complex modifications」タブの「Add rule」から追加したものを「Enable」ボタンで有効化します。

【クリックでコードを展開/閉じる】

karabiner-conf.json

{
    "title": "Karabiner Settings",
    "rules": [
        {
            "description": "left_control to right_command(without VMWare)",
            "manipulators": [
                {
                    "type": "basic",
                    "from": {
                        "key_code": "left_control",
                        "modifiers": {
                            "optional": [
                                "any"
                            ]
                        }
                    },
                    "to": [
                        {
                            "key_code": "right_command"
                        }
                    ],
                    "conditions": [
                        {
                            "type": "frontmost_application_unless",
                            "bundle_identifiers": [
                                "^com\\.vmware\\.fusion"
                            ]
                        },
                        {
                            "type": "device_if",
                            "identifiers": [
                                {
                                    "vendor_id": 1278,
                                    "product_id": 514,
                                    "description": "HHKB-BT"
                                }
                            ]
                        }
                    ]
                }
            ]
        },
        {
            "description": "right_command to left_control(without VMWare)",
            "manipulators": [
                {
                    "type": "basic",
                    "from": {
                        "key_code": "right_command",
                        "modifiers": {
                            "optional": [
                                "any"
                            ]
                        }
                    },
                    "to": [
                        {
                            "key_code": "left_control"
                        }
                    ],
                    "conditions": [
                        {
                            "type": "frontmost_application_unless",
                            "bundle_identifiers": [
                                "^com\\.vmware\\.fusion"
                            ]
                        },
                        {
                            "type": "device_if",
                            "identifiers": [
                                {
                                    "vendor_id": 1278,
                                    "product_id": 514,
                                    "description": "HHKB-BT"
                                }
                            ]
                        }
                    ]
                }
            ]
        },
        {
            "description": "Home Key(without VMWare)",
            "manipulators": [
                {
                    "type": "basic",
                    "from": {
                        "key_code": "home"
                    },
                    "to": [
                        {
                            "key_code": "left_arrow",
                            "modifiers": ["right_command"]
                        }
                    ],
                    "conditions": [
                        {
                            "type": "frontmost_application_unless",
                            "bundle_identifiers": [
                                "^com\\.vmware\\.fusion"
                            ]
                        },
                        {
                            "type": "device_if",
                            "identifiers": [
                                {
                                    "vendor_id": 1278,
                                    "product_id": 514,
                                    "description": "HHKB-BT"
                                }
                            ]
                        }
                    ]
                }
            ]
        },
        {
            "description": "End Key(without VMWare)",
            "manipulators": [
                {
                    "type": "basic",
                    "from": {
                        "key_code": "end"
                    },
                    "to": [
                        {
                            "key_code": "right_arrow",
                            "modifiers": ["right_command"]
                        }
                    ],
                    "conditions": [
                        {
                            "type": "frontmost_application_unless",
                            "bundle_identifiers": [
                                "^com\\.vmware\\.fusion"
                            ]
                        },
                        {
                            "type": "device_if",
                            "identifiers": [
                                {
                                    "vendor_id": 1278,
                                    "product_id": 514,
                                    "description": "HHKB-BT"
                                }
                            ]
                        }
                    ]
                }
            ]
        },
        {
            "description": "shift+space to input control(without VMWare)",
            "manipulators": [
                {
                    "type": "basic",
                    "from": {
                        "key_code": "spacebar",
                        "modifiers": {
                            "mandatory": ["left_shift"]
                        }
                    },
                    "to": [
                        {
                            "key_code": "spacebar",
                            "modifiers": ["left_control"]
                        }
                    ],
                    "conditions": [
                        {
                            "type": "frontmost_application_unless",
                            "bundle_identifiers": [
                                "^com\\.vmware\\.fusion"
                            ]
                        },
                        {
                            "type": "device_if",
                            "identifiers": [
                                {
                                    "vendor_id": 1278,
                                    "product_id": 514,
                                    "description": "HHKB-BT"
                                }
                            ]
                        }
                    ]
                }
            ]
        },
        {
            "description": "Pan Screen Right(without VMWare)",
            "manipulators": [
                {
                    "type": "basic",
                    "from": {
                        "key_code": "right_arrow",
                        "modifiers": {
                            "mandatory": ["right_command"]
                        }
                    },
                    "to": [
                        {
                            "key_code": "right_arrow",
                            "modifiers": ["left_control"]
                        }
                    ],
                    "conditions": [
                        {
                            "type": "frontmost_application_unless",
                            "bundle_identifiers": [
                                "^com\\.vmware\\.fusion"
                            ]
                        },
                        {
                            "type": "device_if",
                            "identifiers": [
                                {
                                    "vendor_id": 1278,
                                    "product_id": 514,
                                    "description": "HHKB-BT"
                                }
                            ]
                        }
                    ]
                }
            ]
        },
        {
            "description": "Pan Screen Left(without VMWare)",
            "manipulators": [
                {
                    "type": "basic",
                    "from": {
                        "key_code": "left_arrow",
                        "modifiers": {
                            "mandatory": ["right_command"]
                        }
                    },
                    "to": [
                        {
                            "key_code": "left_arrow",
                            "modifiers": ["left_control"]
                        }
                    ],
                    "conditions": [
                        {
                            "type": "frontmost_application_unless",
                            "bundle_identifiers": [
                                "^com\\.vmware\\.fusion"
                            ]
                        },
                        {
                            "type": "device_if",
                            "identifiers": [
                                {
                                    "vendor_id": 1278,
                                    "product_id": 514,
                                    "description": "HHKB-BT"
                                }
                            ]
                        }
                    ]
                }
            ]
        }
    ]
}

主な設定について

主な設定としては以下の通りです。

  • CtrlキーとCommandキーの入れ替え
    • これが主に設定したかったものです。
  • HomeキーとEndキーの設定
    • Macにはないらしいので、好みで設定しています。
  • Shift+SpaceキーでのIME切り替え
    • 個人的にこのキーをIMEの切り替えに利用しているので、設定しています。
  • スクリーンのパン設定
    • これがちょっと設定に苦労しました。元々はCtrl+Fn+矢印の設定されているキー(;など)の組み合わせです。

また、全体的に「VMware Fusionでは無効」とし、「ハードウェアはHHKBに限定」とするようにしています。(かなり冗長な記述なので、できれば改善したい…)

設定したデバイスIDなどの情報については、Karabiner-Elementsのインストール時に同時にインストールされたKarabiner-EventViewerで確認できました。

また、Karabiner-Elementsの設定として「Function keys」の設定は特に特殊な割り当ては不要(むしろ困る)だったので「Use all F1, F2, etc. keys as standard function keys」はONにしています。

その他の設定について

その他、以下のような設定も実施しました。

VS Codeのキーボードショートカット

こちらについては、以下のエントリを参考にさせていただき、設定はまるっとそのまま適用しています。

Spotlight検索

ちょっとSpotlight検索がやっかいで、VS Codeでコードを書いている時に.の後でショートカットキーでサジェスト表示させたい場合、Spotlight検索が同時に表示される事象がありました。(こちらも上記エントリで言及されていました

こちらについては、Macのキーボードショートカットを設定し、Shift+Command+Spaceに変更して対応しました。(実際に押すキーはShift+Ctrl+Space

まとめ

以上、Windows使いがKarabiner Elementsの設定をしてみました。これで大体困らずに作業ができているので、しばらく様子をみつつ、なにかあったら追記していきたいと思っています。

どなたかのお役に立てば幸いです。それでは!