Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to enable rules only for specific keyboard layout (karabiner)? #2272

Closed
avatar-lavventura opened this issue May 9, 2020 · 6 comments

Comments

@avatar-lavventura
Copy link

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.

Link: https://stackoverflow.com/q/60329520/2402577

@thoelze1
Copy link

Take a look at the device_if example and the Conditions documentation

@avatar-lavventura
Copy link
Author

avatar-lavventura commented May 12, 2020

On my end actually I just want to disable Swap {} and [] when I am using Turkish keyboard but enable it when I am using U.S. keyboard.

I couldn't find the code for the examples on the first link. On which file should I make the changes, on ~/.config/karabiner/karabiner.json ?

@thoelze1
Copy link

So you have a rule called Swap {} and []? How did you add it?

@avatar-lavventura
Copy link
Author

avatar-lavventura commented May 12, 2020

Usıng import with the help of this answer: ( https://stackoverflow.com/a/60286402/2402577 ). Like for coding I use U.S. keyboard but if I switch to different languagle it makes swapped characters upper case when I press . In turkish keyboard [ is assigned to ğ

@thoelze1
Copy link

If you imported the rule, then it is saved as a json file in ~/.config/karabiner/assets/complex_modifications/, as something like ~/.config/karabiner/assets/complex_modifications/1589318523.json. This json file stores the rules as elements in manipulators. To each of these manipulators elements, you need to add a conditions item that checks what language your keyboard is. I think you should use input_source_if for this.

So the original file looks like this:

{
  "description": "Swap {} and []",
  "manipulators": [
    {
      "type": "basic",
      "from": {
        "key_code": "open_bracket"
      },
      "to": [
        {
          "modifiers": ["left_shift"],
          "key_code": "open_bracket"
        }
      ]
    },
    ...
}

You should modify each of the manipulators so it looks something like this:

{
  "description": "Swap {} and []",
  "manipulators": [
    {
      "type": "basic",
      "conditions": [
        {
          "type": "input_source_if",
          "input_sources": [
            {
              "language": "en"
            }
          ]
        }
      ], 
      "from": {
        "key_code": "open_bracket"
      },
      "to": [
        {
          "modifiers": ["left_shift"],
          "key_code": "open_bracket"
        }
      ]
    },
    ...
}

This way, if the input language is English, then the brackets will be swapped. Otherwise, the swapping won't happen. If this is the opposite of what you want, then you can replace the en with tr (I think). I haven't tried this code but I think it's what you want.

@avatar-lavventura
Copy link
Author

Thanks @thoelze1, it took some time to code it in json but it works. I just added if cases for the en.

I share the gist link in case if someone might need it in future: https://gist.github.com/avatar-lavventura/3c6f3b07a08c66a5bfd5222617d2729c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants