LoginSignup
2
0

More than 5 years have passed since last update.

Karabiner-Elements:キーボードのアローキーをマウスにしてみた

Last updated at Posted at 2018-01-20

はじめに

Karabiner時代にキーボードをマウスにして喜んでいたのですが、macOSをHigh Sierraにして使えなくなって絶望しました。
しかし、最近Karabiner-ElementsのComplex Modificationsが熱いというのを耳にして調べてみると、なんだかマウスが実装できそう!

ということで、オリジナルJsonファイル作ってみました。

機能

  • アローキーでポインタを操作
  • スラッシュで左クリック
  • シフトキーで右クリック
  • Mキー長押しでマウス機能のON/OFFトグル

こんな感じです。

ソースコード

{
    "title": "Key-Mouse Rules",
    "rules": [
        {
            "description": "Use mouse pointing by ←↑→↓",
            "manipulators": [
                {
                    "conditions": [ { "name": "key_mouse_state", "type": "variable_if", "value": 0 } ],
                    "description": "turn on Key-Mouse",
                    "from": { "key_code": "m", "modifiers": { "optional": ["any"] } },
                    "parameters": {
                        "basic.to_if_alone_timeout_milliseconds": 250,
                        "basic.to_if_held_down_threshold_milliseconds": 250
                    },
                    "to_if_alone": [ { "key_code": "m" } ],
                    "to_if_held_down": [ { "set_variable": { "name": "key_mouse_state", "value": 1 } } ],
                    "type": "basic"
                },
                {
                    "conditions": [ { "name": "key_mouse_state", "type": "variable_if", "value": 1 } ],
                    "description": "turn off Key-Mouse",
                    "from": { "key_code": "m", "modifiers": { "optional": ["any"] } },
                    "parameters": {
                        "basic.to_if_alone_timeout_milliseconds": 250,
                        "basic.to_if_held_down_threshold_milliseconds": 250
                    },
                    "to_if_alone": [ { "key_code": "m" } ],
                    "to_if_held_down": [ { "set_variable": { "name": "key_mouse_state", "value": 0 } } ],
                    "type": "basic"
                },
                {
                    "conditions": [ { "name": "key_mouse_state", "type": "variable_if", "value": 1 } ],
                    "description": "/ -> left click",
                    "from": { "key_code": "slash" },
                    "to": [ { "pointing_button": "button1" } ],
                    "type": "basic"
                },
                {
                    "conditions": [ { "name": "key_mouse_state", "type": "variable_if", "value": 1 } ],
                    "description": "right shift -> right click",
                    "from": { "key_code": "right_shift" },
                    "to": [ { "pointing_button": "button2" } ],
                    "type": "basic"
                },
                {
                    "conditions": [ { "name": "key_mouse_state", "type": "variable_if", "value": 1 } ],
                    "description": "← -> mouse left",
                    "from": { "key_code": "left_arrow" },
                    "parameters": {
                        "basic.to_if_held_down_threshold_milliseconds": 800
                    },
                    "to": [ { "mouse_key": { "x": -1000 } } ],
                    "to_if_held_down": [ { "mouse_key": { "x": -2000 } } ],
                    "type": "basic"
                },
                {
                    "conditions": [ { "name": "key_mouse_state", "type": "variable_if", "value": 1 } ],
                    "description": "↑ -> mouse up",
                    "from": { "key_code": "up_arrow" },
                    "parameters": {
                        "basic.to_if_held_down_threshold_milliseconds": 800
                    },
                    "to": [ { "mouse_key": { "y": -1000 } } ],
                    "to_if_held_down": [ { "mouse_key": { "y": -2000 } } ],
                    "type": "basic"
                },
                {
                    "conditions": [ { "name": "key_mouse_state", "type": "variable_if", "value": 1 } ],
                    "description": "→ -> mouse right",
                    "from": { "key_code": "right_arrow" },
                    "parameters": {
                        "basic.to_if_held_down_threshold_milliseconds": 800
                    },
                    "to": [ { "mouse_key": { "x": 1000 } } ],
                    "to_if_held_down": [ { "mouse_key": { "x": 2000 } } ],
                    "type": "basic"
                },
                {
                    "conditions": [ { "name": "key_mouse_state", "type": "variable_if", "value": 1 } ],
                    "description": "↓ -> mouse down",
                    "from": { "key_code": "down_arrow" },
                    "parameters": {
                        "basic.to_if_held_down_threshold_milliseconds": 800
                    },
                    "to": [ { "mouse_key": { "y": 1000 } } ],
                    "to_if_held_down": [ { "mouse_key": { "y": 2000 } } ],
                    "type": "basic"
                }
            ]
        }
    ]
}

スクロールはmacに元からあるスペースキーのやつでできるので省きました。

苦労

任意のキーを長押しで機能のトグルを行いたかったのですが、できませんでした。いい方法ありませんかね。←いい方法を教えていただきました。

余談

インデントを弓括弧{や角括弧[のたびにしないと、Karabinerに読み込まれないようです。なぜなんでしょう.

おわりに

Karabiner-Elements素晴らしいですね。開発陣あっぱれです。
これからも素敵なKarabinerライフを送りたいです。

2
0
3

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
2
0