pqrs-org / Karabiner-Elements

Karabiner-Elements is a powerful utility for keyboard customization on macOS Sierra (10.12) or later.
https://pqrs.org/osx/karabiner/
The Unlicense
18.6k stars 837 forks source link

If multiple conditions are set in "conditions", is it connected with And or Or? #1966

Closed s-show closed 4 years ago

s-show commented 5 years ago

I configured to display the key map of the DIY keyboard after hitting "Shift-Ctrl-Space" twice.

There are two keyboards I use, "Plaid" and "ErgoDash", and each keyboard has a different keymap. So, as shown in the following code, set vendor_id andproduct_id to match the keyboard. The keymap is now displayed.

    {
      "description": "Double type 'Shift-Ctrl-Space', Open 'CheetSheet for Plaid'.",
      "manipulators": [
        {
          "type": "basic",
          "from": {
            "key_code": "spacebar",
            "modifiers": {
              "mandatory": [
                "control",
                "shift"
              ],
              "optional": [
                "any"
              ]
            }
          },
          "to": [
            {
              "shell_command": "qlmanage -p ~/cheetsheet_plaid.png > /dev/null 2<&1"
            }
          ],
          "conditions": [
            {
              "type": "variable_if",
              "name": "ctrl_shift_space_tapCount",
              "value": 1
            }
          ]
        },
        {
          "type": "basic",
          "from": {
            "key_code": "spacebar",
            "modifiers": {
              "mandatory": [
                "control",
                "shift"
              ],
              "optional": [
                "any"
              ]
            }
          },
          "to": [
            {
              "set_variable": {
                "name": "ctrl_shift_space_tapCount",
                "value": 1
              }
            },
            {
              "key_code": "spacebar",
              "modifiers": [
                "shift",
                "control"
              ]
            }
          ],
          "to_delayed_action": {
            "to_if_invoked": [
              {
                "set_variable": {
                  "name": "ctrl_shift_space_tapCount",
                  "value": 0
                }
              }
            ],
            "to_if_canceled": [
              {
                "set_variable": {
                  "name": "ctrl_shift_space_tapCount",
                  "value": 0
                }
              }
            ]
          },
          "conditions": [
            {
              "type": "device_if",
              "identifiers": [
                {
                  "vendor_id": 5824,
                  "product_id": 10203,
                  "description": "Plaid"
                }
              ]
            },
            {
              "type": "variable_if",
              "name": "ctrl_shift_space_tapCount",
              "value": 0
            }
          ]
        }
      ]
    },
    {
      "description": "Double type 'Shift-Ctrl-Space', Open 'CheetSheet for ErgoDash'.",
      "manipulators": [
        {
          "type": "basic",
          "from": {
            "key_code": "spacebar",
            "modifiers": {
              "mandatory": [
                "control",
                "shift"
              ],
              "optional": [
                "any"
              ]
            }
          },
          "to": [
            {
              "shell_command": "qlmanage -p ~/cheetsheet_ergodash.png > /dev/null 2<&1"
            }
          ],
          "conditions": [
            {
              "type": "variable_if",
              "name": "ctrl_shift_space_tapCount",
              "value": 1
            }
          ]
        },
        {
          "type": "basic",
          "from": {
            "key_code": "spacebar",
            "modifiers": {
              "mandatory": [
                "control",
                "shift"
              ],
              "optional": [
                "any"
              ]
            }
          },
          "to": [
            {
              "set_variable": {
                "name": "ctrl_shift_space_tapCount",
                "value": 1
              }
            },
            {
              "key_code": "spacebar",
              "modifiers": [
                "shift",
                "control"
              ]
            }
          ],
          "to_delayed_action": {
            "to_if_invoked": [
              {
                "set_variable": {
                  "name": "ctrl_shift_space_tapCount",
                  "value": 0
                }
              }
            ],
            "to_if_canceled": [
              {
                "set_variable": {
                  "name": "ctrl_shift_space_tapCount",
                  "value": 0
                }
              }
            ]
          },
          "conditions": [
            {
              "type": "device_if",
              "identifiers": [
                {
                  "vendor_id": 65261,
                  "product_id": 24672,
                  "description": "ErgoDash"
                }
              ]
            },
            {
              "type": "variable_if",
              "name": "ctrl_shift_space_tapCount",
              "value": 0
            }
          ]
        }
      ]
    },

However, after setting as shown in the screenshot below, if "Plaid" is removed and only "ErgoDash" is connected and "Shift-Ctrl-Space" is hit twice, vendor_id andproduct_id do not match { "description": "Double type 'Shift-Ctrl-Space', Open 'CheetSheet for Plaid'."} is executed.

screenshot-20190825-023011

Variables for determining whether the key has been hit twice are {"description": "Double type 'Shift-Ctrl-Space', Open 'CheetSheet for Plaid'."} And {"description": "Double type 'Shift-Ctrl -Space ', Open' CheetSheet for ErgoDash '. "} Will cause this problem?

As a reference material, "vendor_id" and "product_id" of "Plaid" and "ErgoDash" are posted.

screenshot-20190825-023210

s-show commented 5 years ago

上記の質問の日本語版です。(画像の添付は省略します。) Japanese version of the above question. (Attaching images is omitted.)

私は、"Shift-Ctrl-Space"を2連打したら、DIYキーボードのキーマップを表示する設定を行いました。

私が使うキーボードは、"Plaid"と"ErgoDash"の2つであり、それぞれのキーボードでキーマップが異なるため、以下のコードのとおり、vendor_idproduct_idを設定して、キーボードに合ったキーマップを表示するようにしました。

しかし、以下のスクリーンショットのとおり設定したあと、"Plaid"を外して"ErgoDash"だけを接続した状態で"Shift-Ctrl-Space"を2連打すると、vendor_idproduct_idが合致しない{"description": "Double type 'Shift-Ctrl-Space', Open 'CheetSheet for Plaid'."}が実行されます。

キーを2連打したか判定するための変数が{"description": "Double type 'Shift-Ctrl-Space', Open 'CheetSheet for Plaid'."}と{"description": "Double type 'Shift-Ctrl-Space', Open 'CheetSheet for ErgoDash'."}で同じため、こうした問題が起きるのでしょうか?

参考資料として、"Plaid"と"ErgoDash"のvendor_idproduct_idを掲載します。

tekezo commented 5 years ago

About multiple conditions

The multiple conditions (e.g., variable_if and device_if) are combined with "AND".

About your rules

You should add device_if into shell_command manipulator as follows. Without device_if, the first shell_command (for Plaid) will always be applied.

        {
            "type": "basic",
            "from": {
                "key_code": "spacebar",
                "modifiers": {
                    "mandatory": ["control", "shift"],
                    "optional": ["any"]
                }
            },
            "to": [
                {
                    "shell_command": "qlmanage -p ~/cheetsheet_ergodash.png > /dev/null 2<&1"
                }
            ],
            "conditions": [
                {
                    "type": "device_if",
                    "identifiers": [
                        {
                            "vendor_id": 5824,
                            "product_id": 10203,
                            "description": "Plaid"
                        }
                    ]
                },
                {
                    "type": "variable_if",
                    "name": "ctrl_shift_space_tapCount",
                    "value": 1
                }
            ]
        },