Search code examples
keyboardkey-bindingskarabiner

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


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.


Solution

  • 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"
            }
        ]
        }
    },