JIS配列のMacをUS配列のように使ったり、RDP接続時にCmdとAltを入れ替える設定

家ではUS配列のキーボードだけど、会社のMacはJIS配列って方は結構いるんじゃないでしょうか。

[Karabiner-Elements](https://karabiner-elements.pqrs.org/)の利用が許可されてるっていうのが条件になりますが、今はこんな設定に落ち着いてます。

- US配列の外付けキーボード(US Keyboard)
- JIS配列（JIS Keyboard）
- JIS配列をUS配列っぽく使うレイアウト(JIS modified)

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/4016042/24be02d8-91d4-4a5b-bd90-b7f9b71a3cc9.png)

MacからWindowsにリモートデスクトップ接続すると、AltとWindowsキーの位置がよくある並びと逆になってしまうのが地味に使いづらく、思わぬ打ち間違いも怖いですよね。
そこで、リモートデスクトップ接続先ではAltとCmdの配置が入れ替わる設定も仕込んでます。

JIS配列の刻印通りになる設定は、Macを他の人に操作してもらう時のため。


``` karabiner.json
{
    "profiles": [
        {
            "complex_modifications": {
                "rules": [
                    {
                        "description": "Swap right command and control in virtual machine/remote desktop",
                        "manipulators": [
                            {
                                "conditions": [
                                    {
                                        "bundle_identifiers": [
                                            "^com\\.microsoft\\.rdc$",
                                            "^com\\.microsoft\\.rdc\\.",
                                            "^net\\.sf\\.cord$",
                                            "^com\\.thinomenon\\.RemoteDesktopConnection$",
                                            "^com\\.itap-mobile\\.qmote$",
                                            "^com\\.nulana\\.remotixmac$",
                                            "^com\\.p5sys\\.jump\\.mac\\.viewer$",
                                            "^com\\.p5sys\\.jump\\.mac\\.viewer\\.",
                                            "^com\\.teamviewer\\.TeamViewer$",
                                            "^com\\.vmware\\.horizon$",
                                            "^com\\.2X\\.Client\\.Mac$",
                                            "^com\\.OpenText\\.Exceed-TurboX-Client$",
                                            "^com\\.realvnc\\.vncviewer$",
                                            "^com\\.vmware\\.fusion$",
                                            "^com\\.vmware\\.horizon$",
                                            "^com\\.vmware\\.view$",
                                            "^com\\.parallels\\.desktop$",
                                            "^com\\.parallels\\.vm$",
                                            "^com\\.parallels\\.desktop\\.console$",
                                            "^org\\.virtualbox\\.app\\.VirtualBoxVM$",
                                            "^com\\.citrix\\.XenAppViewer$",
                                            "^com\\.vmware\\.proxyApp\\.",
                                            "^com\\.parallels\\.winapp\\.",
                                            "^com\\.geekspiff\\.chickenofthevnc$",
                                            "^net\\.sourceforge\\.chicken$",
                                            "^de\\.jinx\\.JollysFastVNC\\.",
                                            "^com\\.realvnc\\.vncviewer\\."
                                        ],
                                        "type": "frontmost_application_if"
                                    }
                                ],
                                "from": {
                                    "key_code": "right_alt",
                                    "modifiers": { "optional": ["any"] }
                                },
                                "to": [{ "key_code": "right_command" }],
                                "type": "basic"
                            },
                            {
                                "conditions": [
                                    {
                                        "bundle_identifiers": [
                                            "^com\\.microsoft\\.rdc$",
                                            "^com\\.microsoft\\.rdc\\.",
                                            "^net\\.sf\\.cord$",
                                            "^com\\.thinomenon\\.RemoteDesktopConnection$",
                                            "^com\\.itap-mobile\\.qmote$",
                                            "^com\\.nulana\\.remotixmac$",
                                            "^com\\.p5sys\\.jump\\.mac\\.viewer$",
                                            "^com\\.p5sys\\.jump\\.mac\\.viewer\\.",
                                            "^com\\.teamviewer\\.TeamViewer$",
                                            "^com\\.vmware\\.horizon$",
                                            "^com\\.2X\\.Client\\.Mac$",
                                            "^com\\.OpenText\\.Exceed-TurboX-Client$",
                                            "^com\\.realvnc\\.vncviewer$",
                                            "^com\\.vmware\\.fusion$",
                                            "^com\\.vmware\\.horizon$",
                                            "^com\\.vmware\\.view$",
                                            "^com\\.parallels\\.desktop$",
                                            "^com\\.parallels\\.vm$",
                                            "^com\\.parallels\\.desktop\\.console$",
                                            "^org\\.virtualbox\\.app\\.VirtualBoxVM$",
                                            "^com\\.citrix\\.XenAppViewer$",
                                            "^com\\.vmware\\.proxyApp\\.",
                                            "^com\\.parallels\\.winapp\\.",
                                            "^com\\.geekspiff\\.chickenofthevnc$",
                                            "^net\\.sourceforge\\.chicken$",
                                            "^de\\.jinx\\.JollysFastVNC\\.",
                                            "^com\\.realvnc\\.vncviewer\\."
                                        ],
                                        "type": "frontmost_application_if"
                                    }
                                ],
                                "from": {
                                    "key_code": "right_command",
                                    "modifiers": { "optional": ["any"] }
                                },
                                "to": [{ "key_code": "right_alt" }],
                                "type": "basic"
                            }
                        ]
                    },
                    {
                        "description": "Swap left command and control in virtual machine/remote desktop",
                        "manipulators": [
                            {
                                "conditions": [
                                    {
                                        "bundle_identifiers": [
                                            "^com\\.microsoft\\.rdc$",
                                            "^com\\.microsoft\\.rdc\\.",
                                            "^net\\.sf\\.cord$",
                                            "^com\\.thinomenon\\.RemoteDesktopConnection$",
                                            "^com\\.itap-mobile\\.qmote$",
                                            "^com\\.nulana\\.remotixmac$",
                                            "^com\\.p5sys\\.jump\\.mac\\.viewer$",
                                            "^com\\.p5sys\\.jump\\.mac\\.viewer\\.",
                                            "^com\\.teamviewer\\.TeamViewer$",
                                            "^com\\.vmware\\.horizon$",
                                            "^com\\.2X\\.Client\\.Mac$",
                                            "^com\\.OpenText\\.Exceed-TurboX-Client$",
                                            "^com\\.realvnc\\.vncviewer$",
                                            "^com\\.vmware\\.fusion$",
                                            "^com\\.vmware\\.horizon$",
                                            "^com\\.vmware\\.view$",
                                            "^com\\.parallels\\.desktop$",
                                            "^com\\.parallels\\.vm$",
                                            "^com\\.parallels\\.desktop\\.console$",
                                            "^org\\.virtualbox\\.app\\.VirtualBoxVM$",
                                            "^com\\.citrix\\.XenAppViewer$",
                                            "^com\\.vmware\\.proxyApp\\.",
                                            "^com\\.parallels\\.winapp\\.",
                                            "^com\\.geekspiff\\.chickenofthevnc$",
                                            "^net\\.sourceforge\\.chicken$",
                                            "^de\\.jinx\\.JollysFastVNC\\.",
                                            "^com\\.realvnc\\.vncviewer\\."
                                        ],
                                        "type": "frontmost_application_if"
                                    }
                                ],
                                "from": {
                                    "key_code": "left_alt",
                                    "modifiers": { "optional": ["any"] }
                                },
                                "to": [{ "key_code": "left_command" }],
                                "type": "basic"
                            },
                            {
                                "conditions": [
                                    {
                                        "bundle_identifiers": [
                                            "^com\\.microsoft\\.rdc$",
                                            "^com\\.microsoft\\.rdc\\.",
                                            "^net\\.sf\\.cord$",
                                            "^com\\.thinomenon\\.RemoteDesktopConnection$",
                                            "^com\\.itap-mobile\\.qmote$",
                                            "^com\\.nulana\\.remotixmac$",
                                            "^com\\.p5sys\\.jump\\.mac\\.viewer$",
                                            "^com\\.p5sys\\.jump\\.mac\\.viewer\\.",
                                            "^com\\.teamviewer\\.TeamViewer$",
                                            "^com\\.vmware\\.horizon$",
                                            "^com\\.2X\\.Client\\.Mac$",
                                            "^com\\.OpenText\\.Exceed-TurboX-Client$",
                                            "^com\\.realvnc\\.vncviewer$",
                                            "^com\\.vmware\\.fusion$",
                                            "^com\\.vmware\\.horizon$",
                                            "^com\\.vmware\\.view$",
                                            "^com\\.parallels\\.desktop$",
                                            "^com\\.parallels\\.vm$",
                                            "^com\\.parallels\\.desktop\\.console$",
                                            "^org\\.virtualbox\\.app\\.VirtualBoxVM$",
                                            "^com\\.citrix\\.XenAppViewer$",
                                            "^com\\.vmware\\.proxyApp\\.",
                                            "^com\\.parallels\\.winapp\\.",
                                            "^com\\.geekspiff\\.chickenofthevnc$",
                                            "^net\\.sourceforge\\.chicken$",
                                            "^de\\.jinx\\.JollysFastVNC\\.",
                                            "^com\\.realvnc\\.vncviewer\\."
                                        ],
                                        "type": "frontmost_application_if"
                                    }
                                ],
                                "from": {
                                    "key_code": "left_command",
                                    "modifiers": { "optional": ["any"] }
                                },
                                "to": [{ "key_code": "left_alt" }],
                                "type": "basic"
                            }
                        ]
                    },
                    {
                        "description": "コマンドキーを単体で押したときに、英数・かなキーを送信する。（左コマンドキーは英数、右コマンドキーはかな） (rev 3)",
                        "manipulators": [
                            {
                                "from": {
                                    "key_code": "left_command",
                                    "modifiers": { "optional": ["any"] }
                                },
                                "parameters": { "basic.to_if_held_down_threshold_milliseconds": 100 },
                                "to": [
                                    {
                                        "key_code": "left_command",
                                        "lazy": true
                                    }
                                ],
                                "to_if_alone": [{ "key_code": "japanese_eisuu" }],
                                "to_if_held_down": [{ "key_code": "left_command" }],
                                "type": "basic"
                            },
                            {
                                "from": {
                                    "key_code": "right_command",
                                    "modifiers": { "optional": ["any"] }
                                },
                                "parameters": { "basic.to_if_held_down_threshold_milliseconds": 100 },
                                "to": [
                                    {
                                        "key_code": "right_command",
                                        "lazy": true
                                    }
                                ],
                                "to_if_alone": [{ "key_code": "japanese_kana" }],
                                "to_if_held_down": [{ "key_code": "right_command" }],
                                "type": "basic"
                            }
                        ]
                    }
                ]
            },
            "devices": [
                {
                    "identifiers": {
                        "is_keyboard": true,
                        "product_id": 591,
                        "vendor_id": 1452
                    },
                    "simple_modifications": [
                        {
                            "from": { "key_code": "caps_lock" },
                            "to": [{ "key_code": "left_control" }]
                        }
                    ]
                },
                {
                    "identifiers": {
                        "is_keyboard": true,
                        "is_pointing_device": true,
                        "product_id": 758,
                        "vendor_id": 13364
                    },
                    "ignore": false,
                    "simple_modifications": [
                        {
                            "from": { "key_code": "caps_lock" },
                            "to": [{ "key_code": "left_control" }]
                        }
                    ]
                },
                {
                    "identifiers": {
                        "is_keyboard": true,
                        "product_id": 758,
                        "vendor_id": 13364
                    },
                    "simple_modifications": [
                        {
                            "from": { "key_code": "caps_lock" },
                            "to": [{ "key_code": "left_control" }]
                        }
                    ]
                },
                {
                    "identifiers": {
                        "is_keyboard": true,
                        "is_pointing_device": true,
                        "product_id": 1809,
                        "vendor_id": 13364
                    },
                    "ignore": false
                },
                {
                    "identifiers": {
                        "is_keyboard": true,
                        "is_pointing_device": true,
                        "product_id": 53287,
                        "vendor_id": 13364
                    },
                    "ignore": false
                }
            ],
            "name": "US Keyboard",
            "selected": true,
            "simple_modifications": [
                {
                    "from": { "key_code": "caps_lock" },
                    "to": [{ "key_code": "left_control" }]
                }
            ],
            "virtual_hid_keyboard": { "keyboard_type_v2": "ansi" }
        },
        {
            "name": "JIS Keyboard (Default)",
            "virtual_hid_keyboard": { "country_code": 45 }
        },
        {
            "complex_modifications": {
                "rules": [
                    {
                        "description": "英数・かなキーを他のキーと組み合わせて押したときに、コマンドキーを送信する。",
                        "manipulators": [
                            {
                                "from": {
                                    "key_code": "japanese_eisuu",
                                    "modifiers": { "optional": ["any"] }
                                },
                                "to": [{ "key_code": "left_command" }],
                                "to_if_alone": [{ "key_code": "japanese_eisuu" }],
                                "type": "basic"
                            },
                            {
                                "from": {
                                    "key_code": "japanese_kana",
                                    "modifiers": { "optional": ["any"] }
                                },
                                "to": [{ "key_code": "right_command" }],
                                "to_if_alone": [{ "key_code": "japanese_kana" }],
                                "type": "basic"
                            },
                            {
                                "from": {
                                    "key_code": "right_command",
                                    "modifiers": { "optional": ["any"] }
                                },
                                "to": [{ "key_code": "right_command" }],
                                "to_if_alone": [{ "key_code": "japanese_kana" }],
                                "type": "basic"
                            }
                        ]
                    },
                    {
                        "description": "バッククオートとチルダを割り当てる。",
                        "manipulators": [
                            {
                                "from": {
                                    "key_code": "international3",
                                    "modifiers": { "optional": ["any"] }
                                },
                                "to": [{ "key_code": "grave_accent_and_tilde" }],
                                "type": "basic"
                            }
                        ]
                    },
                    {
                        "description": "コマンドキーを単体で押したときに、英数・かなキーを送信する。（左コマンドキーは英数、右コマンドキーはかな） (rev 3)",
                        "manipulators": [
                            {
                                "from": {
                                    "key_code": "left_command",
                                    "modifiers": { "optional": ["any"] }
                                },
                                "parameters": { "basic.to_if_held_down_threshold_milliseconds": 100 },
                                "to": [
                                    {
                                        "key_code": "left_command",
                                        "lazy": true
                                    }
                                ],
                                "to_if_alone": [{ "key_code": "japanese_eisuu" }],
                                "to_if_held_down": [{ "key_code": "left_command" }],
                                "type": "basic"
                            },
                            {
                                "from": {
                                    "key_code": "right_command",
                                    "modifiers": { "optional": ["any"] }
                                },
                                "parameters": { "basic.to_if_held_down_threshold_milliseconds": 100 },
                                "to": [
                                    {
                                        "key_code": "right_command",
                                        "lazy": true
                                    }
                                ],
                                "to_if_alone": [{ "key_code": "japanese_kana" }],
                                "to_if_held_down": [{ "key_code": "right_command" }],
                                "type": "basic"
                            }
                        ]
                    }
                ]
            },
            "devices": [
                {
                    "identifiers": {
                        "is_keyboard": true,
                        "product_id": 634,
                        "vendor_id": 1452
                    },
                    "simple_modifications": [
                        {
                            "from": { "key_code": "caps_lock" },
                            "to": [{ "apple_vendor_top_case_key_code": "keyboard_fn" }]
                        }
                    ]
                },
                {
                    "identifiers": {
                        "is_keyboard": true,
                        "is_pointing_device": true,
                        "product_id": 53287,
                        "vendor_id": 13364
                    },
                    "ignore": false
                }
            ],
            "name": "JIS modified",
            "simple_modifications": [
                {
                    "from": { "key_code": "international1" },
                    "to": [{ "key_code": "grave_accent_and_tilde" }]
                }
            ],
            "virtual_hid_keyboard": { "keyboard_type_v2": "ansi" }
        }
    ]
}
```