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

1.6k Views Asked by At

On Karabiner I am enabling multiples rules under its complex modifications setup, such as Emacs key bindings.

I was wondering is it possible to use those enables rules only for a specific keyboard layout such as U.S. and automatically disable those rules when I switch to an another keyboard layout.

2

There are 2 best solutions below

0
On BEST ANSWER

From this guide

Take a look at the device_if example and the Conditions documentation


I added following code into ~/.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"
        }
    ]
    }
},
2
On

It's not possible to turn existing imported rules to be device specific. However if you make or modify those rules you can.

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

The gist of how to make your own rules is making a json file inside

~/.config/karabiner/assets/complex_modifications/

You can name the json file whatever you want. you can even symlink it from another place if you prefer.

So if you have a rule you want to make device specific, copy paste it inside your json file and modify it from type: "basic" to to type: "device_if" and fill up your device id etc. which you can get from the Karabiner EventViewer app under devices tab.