如何仅为特定的键盘布局(karabiner)启用规则?

How to enable rules only for specific keyboard layout (karabiner)?

在 Karabiner 上,我在其复杂的修改设置下启用了多个规则,例如 Emacs key bindings

我想知道是否可以只对特定的键盘布局使用这些启用规则,例如 U.S.,并在我切换到另一个键盘布局时自动禁用这些规则。

无法将现有的导入规则转为特定于设备。但是,如果您制定或修改这些规则,则可以。

https://pqrs.org/osx/karabiner/json.html#condition-definition-device

如何制定自己的规则的要点是在

中创建一个 json 文件
~/.config/karabiner/assets/complex_modifications/

您可以随意命名 json 文件。如果愿意,您甚至可以从其他地方对其进行符号链接。

所以如果你有一个规则你想使设备特定,将它复制粘贴到你的 json 文件中并将它从 type: "basic" 修改为 type: "device_if" 并填满你的设备您可以从设备选项卡下的 Karabiner EventViewer 应用程序获取 ID 等。

由此guide

Take a look at the device_if example and the Conditions documentation


我在 ~/.config/karabiner/karabiner.json

中添加了以下代码
{
    "manipulators": [
        {
            "conditions": [
                {
                    "input_sources": [
                        {
                            "language": "en"
                        }
                    ],
                    "type": "input_source_if"
                }
            ],

            "from": {
                "key_code": "open_bracket"
            },
            "to": [
                {
                    "key_code": "open_bracket",
                    "modifiers": [
                        "left_shift"
                    ]
                }
            ],
            "type": "basic"
        },
        {
            "conditions": [
                {
                    "input_sources": [
                        {
                            "language": "en"
                        }
                    ],
                    "type": "input_source_if"
                }
            ],
            "from": {
                "key_code": "close_bracket",
                "modifiers": {
                    "mandatory": [
                        "left_shift"
                    ]
                }
            },
            "to": [
                {
                    "key_code": "close_bracket"
                }
            ],
            "type": "basic"
        },
        {
            "conditions": [
                {
                    "input_sources": [
                        {
                            "language": "en"
                        }
                    ],
                    "type": "input_source_if"
                }
            ],
            "from": {
                "key_code": "close_bracket"
            },
            "to": [
                {
                    "key_code": "close_bracket",
                    "modifiers": [
                        "left_shift"
                    ]
                }
            ],
            "type": "basic"
        },
        {
            "conditions": [
                {
                    "input_sources": [
                        {
                            "language": "en"
                        }
                    ],
                    "type": "input_source_if"
                }
            ],
            "from": {
                "key_code": "open_bracket",
                "modifiers": {
                    "mandatory": [
                        "left_shift"
                    ]
                }
            },
            "to": [
                {
                    "key_code": "open_bracket"
                }
            ],
            "type": "basic"
        }
    ]
    }
},