Karabinerでfnキーに3つの機能を持たせた

2023-04-30
#karabiner #macos
  1. 経緯
  2. 実装
  3. 使い道
    1. Mission Control
    2. ProxKey
    3. fn
  4. まとめ

経緯

キーボードのfnキーがもったいないと感じていた。ほとんど使っていなかったので、もっと活用できないかと考えた。

Karabiner-Elementsを使えば、単一のキーに複数の機能を持たせることができる。今回はfnキーに3つの動作を割り当てることにした。

実装

作成した設定は以下の通り。

{
  "description": "fn単体 → Mission Control、組み合わせ → Prox key (Alt+Ctrl+⌘)、長押し → fn",
  "manipulators": [
    {
      "from": {
        "key_code": "fn",
        "modifiers": { "optional": ["left_shift"] }
      },
      "to": [
        {
          "key_code": "left_command",
          "modifiers": ["left_control", "left_option"]
        }
      ],
      "to_if_alone": [{ "key_code": "mission_control" }],
      "to_if_held_down": [
        {
          "halt": true,
          "key_code": "fn"
        }
      ],
      "type": "basic"
    }
  ]
},

この設定により、fnキーは以下のように動作する。

  1. 単体で押した場合: Mission Controlが起動

  2. 他のキーと組み合わせた場合: Alt+Ctrl+⌘(ProxKey)として動作

  3. 長押しの場合: 通常のfnキーになる

使い道

Mission Control

fnキーを軽くタップするだけでMission Controlが起動できる。開いているウィンドウを一覧表示できるので、アプリケーション間の切り替えが楽になった。

ProxKey

Alt+Ctrl+⌘ の組み合わせは「ProxKey」と呼ぶことにした。Hyper key(Ctrl+Shift+Alt+⌘)やMeh key(Ctrl+Shift+Alt)とは異なる組み合わせで、特定のアプリケーションでの使用を想定している。名前は「Proximity」(近接性)から。

ProxKeyは他のアプリケーションとキーバインドが競合しにくいため、主にRaycastのショートカットに利用している。

Raycastのホットキー設定でProxKeyとの組み合わせを割り当てることで、統一的なショートカット体系を構築できた。

fn

長押しすれば通常のfnキーとして動作するので、fn+Delete(前方削除)や fn+矢印キー(Home/End)もそのまま使える。

まとめ

Karabinerの to_if_aloneto_if_held_down を使うことで、1つのキーに3つの役割を持たせることができた。

to_if_alone | Karabiner-Elements

to_if_alone posts events when the from key is pressed alone. The events are posted at the from key is released. Example The following json changes left_control to sending escape when left_control is pressed alone. 💡 How to use this example { "description": "Send the escape key when the left control key is tapped", "manipulators": [ { "type": "basic", "from": { "key_code": "left_control", "modifiers": { "optional": ["any"] } }, "to": [ { "key_code": "left_control" } ], "to_if_alone": [{ "key_code": "escape" }] } ] } About cancellation to_if_alone is canceled if other events (keys, buttons or scroll wheel) is happen while the from key is pressed down.

karabiner-elements.pqrs.org