LoginSignup
16
22

More than 5 years have passed since last update.

USキーボードの左右Commandキーで仮想化Windowsの英数/かな入力を切り替える

Last updated at Posted at 2017-08-03

Mac(US Keyboard)+Karabiner+仮想化Windows(Parallels Desktop)

ある時「英数/かなキーって要らなくね?Commandとまとめた方が良くね?」と思い、それ以降USキーボード+Karabinerの設定により、左右Commandキーを単体で押すと英数/かなキー(左Commandは英数、右Commandはかな)として、Commandキーと何かを組み合わせた場合は、通常のCommandキーとして使用するという非常に快適なMacライフを謳歌していたのですが、macOS Sierra以降、その仕組みの要であるKarabinerが動かなくなってしまいました。

英かなのお世話になったり、Command+Spaceで切り替えることに慣れようとしてみたり・・・
あれほどまでに「要らない」と思っていた「英数/かなキー」が、こんなに恋しくなるなんて。大事なものは無くしてから初めて気付くのだと、改めて感じました。

また、ごく稀にParallels Desktopに構築したWindowsを使用することもあったので、下記のサイトなどを参考にして、快適なWindowsライフも謳歌していました。が、これもKarabinerが動かなくなってしまい・・・大事なものは

▼USキーのMacでWindowsをJISキーのMacぽく使う方法http://ysnhrk.blogspot.com/2013/10/usmacwindowsjismac.html
▼ParallelsのWindowsでUSキーボードを使う
http://d.hatena.ne.jp/iicebar/20140915/1410800172

あんまりごちゃごちゃ書いても仕方ないので、以下ササっと書きます。

動作環境

  • Mac
    • MacBook Pro (15-inch, 2016)
    • macOS Sierra(10.12.6)
  • Karabiner-Elements
    • Version 0.91.12
  • Parallels Desktop
    • Parallels Desktop 12 for Mac Pro Edition Version 12.2.1(41615)
  • Windows(仮想化)
    • Windows 10 Pro
    • バージョン 1703
    • OSビルド 15063.483

方策

  1. Macでは、Karabiner-Elementsの公式で配布されている「For Japanese(日本語環境向けの設定)」を適用した場合と同じ動作をするようにする
  2. Parallels Desktop上のWindowsでも、左Commandを単体で押すとIMEオフ、右Commandを単体で押すとIMEオン、Commandと何かを組み合わせると、CommandキーがControlキーとして動作するようにする

Karabiner-Elementsの設定

下記のjsonファイルを~/.config/karabiner/assets/complex_modificationsに保存し、Karabiner-Elementsのcomplex-modificationsタブからAdd ruleすれば、Karabiner-Elementsの設定は完了です。

japanese(custom).json
{
  "title": "For Japanese (日本語環境向けの設定)+ Parallels Desktop(Win)",
  "rules": [
    { "description": "コマンドキーを単体で押したときに、英数・かなキーを送信する。(左コマンドキーは英数、右コマンドキーはかな)",
      "manipulators": [
        { "type": "basic",
          "from": { "key_code": "left_command",
                    "modifiers": { "optional": [ "any" ] } },
          "to": [ { "key_code": "left_command" } ],
          "to_if_alone": [ { "key_code": "japanese_eisuu" } ],
          "conditions": [ { "type": "frontmost_application_unless",
                            "bundle_identifiers": [ "^com\\.parallels\\.desktop$",
                                                    "^com\\.parallels\\.vm$",
                                                    "^com\\.parallels\\.desktop\\.console$",
                                                    "^com\\.parallels\\.winapp\\." ] } ] },
        { "type": "basic",
          "from": { "key_code": "right_command",
                    "modifiers": { "optional": [ "any" ] } },
          "to": [ { "key_code": "right_command" } ],
          "to_if_alone": [ { "key_code": "japanese_kana" } ],
          "conditions": [ { "type": "frontmost_application_unless",
                            "bundle_identifiers": [ "^com\\.parallels\\.desktop$",
                                                    "^com\\.parallels\\.vm$",
                                                    "^com\\.parallels\\.desktop\\.console$",
                                                    "^com\\.parallels\\.winapp\\." ] } ] },
        { "type": "basic",
          "from": { "key_code": "left_command",
                "modifiers": { "optional": [ "any" ] } },
          "to": [ { "key_code": "left_command" } ],
          "to_if_alone": [ { "key_code": "f11",
                             "modifiers": ["left_shift", "left_control"] } ],
          "conditions": [ { "type": "frontmost_application_if",
                            "bundle_identifiers": [ "^com\\.parallels\\.desktop$",
                                                    "^com\\.parallels\\.vm$",
                                                    "^com\\.parallels\\.desktop\\.console$",
                                                    "^com\\.parallels\\.winapp\\." ] } ] },
       { "type": "basic",
         "from": { "key_code": "right_command",
                   "modifiers": { "optional": [ "any" ] } },
         "to": [ { "key_code": "left_command" } ],
         "to_if_alone": [ { "key_code": "f12",
                            "modifiers": ["left_shift", "left_control"] } ],
        "conditions": [ { "type": "frontmost_application_if",
                         "bundle_identifiers": [ "^com\\.parallels\\.desktop$",
                                                 "^com\\.parallels\\.vm$",
                                                 "^com\\.parallels\\.desktop\\.console$",
                                                 "^com\\.parallels\\.winapp\\." ] } ] }
        ]
    }
]
}

公式のjapanese.jsonをそのまま適用し、その上でfrontmost_application_ifの設定を追加しても、公式のjapanese.jsonの設定がParallels Desktop上でも効いてしまうというところに気づかず、ハマっておりました・・・

Windows(IME)の設定

今回はMicrosoft IMEを使用、IMEのオン・オフを左右のCommandキーで切り替えることとしました。

上記までで、左Commandが押されたら「F11+Shift+Ctrl」、右Commandが押されたら「F12+Shift+Ctrl」が送られるように設定がされています。
なので、IMEの設定で、「F11+Shift+Ctrl」が押されたら「IMEオフ」、「F12+Shift+Ctrl」が押されたら「IMEオン」となるように設定をすれば良いです(こちらの「3. Microsoft Office IME2010を開く」をご参照ください)。

Parallels Desktop以外は?

面倒臭手元に環境がなかったので、試せませんでしたがbundle_identifiersの部分を下記のように書けば、動くと思います。

bundle_identifiers
"^com\\.parallels\\.desktop$",
"^com\\.parallels\\.vm$",
"^com\\.parallels\\.desktop\\.console$",
"^com\\.parallels\\.winapp\\.",
"^com\\.vmware\\.fusion$",
"^com\\.vmware\\.horizon$",
"^com\\.vmware\\.view$",
"^com\\.vmware\\.proxyApp\\.",
"^org\\.virtualbox\\.app\\.VirtualBoxVM$"

最後に

この方法で、再び快適なMac&Windowsライフを謳歌することができそうです。
私の環境では過去にKarabinerを使用していた頃と変わらない操作感に戻り、特に問題なく使用できています。問題が出るほどの時間使用していない感もありますが・・・

ただ、これだとWindowsキーが死んでしまうので、その辺はお好みでリマップするなりなんなりしていただければと思います。

とりあえず勢いでババーっと書いてしまったので、間違いや、バッカお前こうしろよ的なものがあれば指摘していただけるとありがたいです。

Karabiner-Elements万歳!感謝!Donateしておきます!

その他参考にさせていただいた記事など

Karabiner-Elements Key Name Definitions
KE-complex_modifications - japanese.json
Karabiner-Elementsの本家が「英数/かな」の切り替えに対応したみたい
Karabiner-Elements が超絶怒濤に進化している。今も!
【人権回復】Karabiner-ElementsでOne-to-many, Many-to-oneマッピング

16
22
7

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
16
22