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

App specific settings possible? #808

Closed
danz54 opened this issue Jul 3, 2017 · 16 comments
Closed

App specific settings possible? #808

danz54 opened this issue Jul 3, 2017 · 16 comments
Labels

Comments

@danz54
Copy link

danz54 commented Jul 3, 2017

Is there a way to implement App-specific settings to change keys?
Thanks

@jonaskello
Copy link

jonaskello commented Jul 6, 2017

Looking for this too.
In old karabiner I used that for remote desktop.
In macos I have switched CTRL and CMD with karabiner elements which works fine.
But when i RDP into a Windows machine the mapping will make Windows use CMD for CTRL and vice-verca.
Bascially I'm looking to have CTRL+C etc. to work the same regardless if I'm using macos or RDP into Windows.

@jixiuf
Copy link

jixiuf commented Jul 10, 2017

it seems supported now


                    {
                        "manipulators": [
                            {
                                "conditions": [
                                    {
                                        "bundle_identifiers": [
                                            "^com\\.apple\\.finder$"
                                        ],
                                        "type": "frontmost_application_if"
                                    }
                                ],
                                "description": "Finder Ctrl-; goto location",
                                "from": {
                                    "key_code": "semicolon",
                                    "modifiers": {
                                        "mandatory": [
                                            "left_control"
                                        ],
                                        "optional": [
                                            "caps_lock",
                                            "shift",
                                            "option"
                                        ]
                                    }
                                },
                                "to": [
                                    {
                                        "key_code": "g",
                                        "modifiers": [
                                            "command",
                                            "shift"
                                        ]
                                    }
                                ],
                                "type": "basic"
                            }
                        ]
                    },

@jonaskello
Copy link

@jixiuf Yes, looks like the conditions section is it. Is there somewhere in the UI we could set this? Or where is the file you are looking at located?

@transamericamoon
Copy link

transamericamoon commented Jul 11, 2017

You can copy this example into ~/.config/karabiner/assets/complex_modifications/windows-binding.json

Got to karabiner preferences->complex Modifications->Add rule and press enable on it.

You can modify it to your liking but make sure you run it through a json validator first.

{
  "title": "Windows keys",
  "rules": [
    {
      "description": "swap control/command fix home/end/redo except for iterm2/vim",
      "manipulators": [
        {
          "type": "basic",
          "from": {
            "key_code": "y",
            "modifiers": {
              "mandatory": [
                "command"
              ]
            }
          },
          "to": [
            {
              "key_code": "z",
              "modifiers": [
                "command",
                "shift"
              ]
            }
          ],
          "conditions": [
            {
              "type": "frontmost_application_unless",
              "bundle_identifiers": [
                "^org\\.vim\\.",
                "^com.googlecode.iterm2"
              ]
            }
          ]
        },
        {
          "type": "basic",
          "from": {
            "key_code": "end"
          },
          "to": [
            {
              "key_code": "e",
              "modifiers": [
                "control"
              ]
            }
          ],
          "conditions": [
            {
              "type": "frontmost_application_unless",
              "bundle_identifiers": [
                "^org\\.vim\\.",
                "^com.googlecode.iterm2"
              ]
            }
          ]
        },
        {
          "type": "basic",
          "from": {
            "key_code": "home"
          },
          "to": [
            {
              "key_code": "a",
              "modifiers": [
                "control"
              ]
            }
          ],
          "conditions": [
            {
              "type": "frontmost_application_unless",
              "bundle_identifiers": [
                "^org\\.vim\\.",
                "^com.googlecode.iterm2"
              ]
            }
          ]
        },
        {
          "type": "basic",
          "from": {
            "key_code": "left_command"
          },
          "to": [
            {
              "key_code": "left_control"
            }
          ],
          "conditions": [
            {
              "type": "frontmost_application_unless",
              "bundle_identifiers": [
                "^org\\.vim\\.",
                "^com.googlecode.iterm2"
              ]
            }
          ]
        },
        {
          "type": "basic",
          "from": {
            "key_code": "left_control"
          },
          "to": [
            {
              "key_code": "left_command"
            }
          ],
          "conditions": [
            {
              "type": "frontmost_application_unless",
              "bundle_identifiers": [
                "^org\\.vim\\.",
                "^com.googlecode.iterm2"
              ]
            }
          ]
        },
        {
          "type": "basic",
          "from": {
            "key_code": "right_command"
          },
          "to": [
            {
              "key_code": "right_control"
            }
          ],
          "conditions": [
            {
              "type": "frontmost_application_unless",
              "bundle_identifiers": [
                "^org\\.vim\\.",
                "^com.googlecode.iterm2"
              ]
            }
          ]
        },
        {
          "type": "basic",
          "from": {
            "key_code": "right_control"
          },
          "to": [
            {
              "key_code": "right_command"
            }
          ],
          "conditions": [
            {
              "type": "frontmost_application_unless",
              "bundle_identifiers": [
                "^org\\.vim\\.",
                "^com.googlecode.iterm2"
              ]
            }
          ]
        }
      ]
    }
  ]
}

@jonaskello
Copy link

Yupp, already done it and it works perfectly :-)

@garbage914
Copy link

This is awesome. Thank you. I have it running in Karibiner elements. Can you please tell me how I would tweak it so that it only works when typing from within Teamviewer?

@garbage914
Copy link

I was given a solution to switch the command and control keys only using team viewer. It is here:
https://forum.keyboardmaestro.com/t/switching-command-and-control-keys/7721/27?u=cinematree

@Palisand
Copy link

Palisand commented Jan 17, 2018

It looks like there is no way to define "conditions" once so it applies to all manipulators?

@stale
Copy link

stale bot commented Mar 18, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@dPowNextdoor
Copy link

Could we possibly re-open this to address @Palisand's comment? It's a huge pain to copy the conditions field into every single entry. It'd be nice if we could have both so we could choose to apply it to all rules or only some rules.

Even better, allow a top-level conditions object in both rules and rules[i].manipulators so it can be applied to all rules or all key maps within individual rules.

Even better, let the inner conditions entries extend (or override if applicable) the outer conditions entries.

@MuhammedZakir
Copy link

I agree a GUI window to modify this will be great. But IMO, I don't think this will be implemented soon as there a couple of serious bugs to be fixed. Meanwhile, you can use Ruby helper scripts [1], or Goku to simplify writing config. Ruby scripts are probably more beginner-friendly. Check .erb files of other users in that repo [2]. But writing in GokuEDN is much more simple once you get used to it.

[1] https://github.com/pqrs-org/KE-complex_modifications/tree/master/src/lib
[2] https://github.com/pqrs-org/KE-complex_modifications/tree/master/src/json

@dPowNextdoor
Copy link

dPowNextdoor commented Jun 24, 2021

Oh no, I'm fine without a GUI. What I meant was to remove the need to have the same condition duplicated superfluously, i.e.

{
    "title": "My key combo with lots of duplicated code that isn't user friendly",
    "rules": [
        {
            "description": "I'm not following the DRY principle :(",
            "manipulators": [
                {
                    "type": "basic",
                    "from": {},
                    "to": [],
                    "conditions": [
                        "duplicate_condition_objects"
                    ]
                },
                {
                    "type": "basic",
                    "from": {},
                    "to": [],
                    "conditions": [
                        "duplicate_condition_objects"
                    ]
                }
            ]
        }
    ]
}

would be replaced with

{
    "title": "My key combo that is user friendly",
    "rules": [
        {
            "description": "Yay, I'm following the DRY principle!",
            "conditions": [
                "unique_condition_objects"
            ],
            "manipulators": [
                {
                    "type": "basic",
                    "from": {},
                    "to": []
                },
                {
                    "type": "basic",
                    "from": {},
                    "to": []
                }
            ]
        }
    ]
}

Even better, we could simultaneously replace the restrictive, non-extensible manipulator priority with one that is very extensible. (I imagine that to implement the first, this format would also have to be implemented, but they're basically the same thing when you think about it.)

{
    "title": "My key combo that is SUPER user friendly",
    "conditions": [
        "default conditions to apply to all rules"
    ],
    "rules": [
        {
            "description": "Wow, this is both DRY and way easier to read!",
            "manipulators": [
                "manipulators without unnecessary code duplication"
            ]
        },
        {
            "description": "Oh cool, I can keep the global rules that I want and delete the ones I don't!",
            "conditions": [
                "Conditions to only apply to this rule's manipulators.",
                "Maintains global, root-level rules",
                "or overrides them if applicable."
            ],
            "manipulators": [
                "yay I'm not duplicating the global rules",
                "nor do I have to add a superfluous frontmost_application_unless",
                "(or similar) conditions to every single entry I contain!",
                {
                    "type": "Even my custom manipulator is easier to write",
                    "from": {},
                    "to": [],
                    "conditions": [
                        "Extra condition to add only for me.",

                        "Alternatively, override the global rule(s) I don't want",
                        "while keeping the rest of them.",

                        "Alternatively, override the rule-level rules",
                        "so the other rules don't have to add",
                        "_unless entries."
                    ]
                }
            ]
        }
    ]
}

This would be an incredibly better way to write rules/conditions, especially since the entries' contents have to be written manually. It also means that similar manipulators can be grouped into one rule instead of spreading their logic across multiple rules (e.g. frontmost_application_unless) and/or breaking because the user accidentally imported them in the wrong order (e.g. frontmost_application_if not working due to a previous/global rule using the same key combo).

@MuhammedZakir
Copy link

That's nice! :-) pinging @tekezo.

@hitriyvalenok
Copy link

+100500 @dPowNextdoor

@dPowNextdoor
Copy link

FYI I just created this issue that would help solve the pain points we've been discussing. Feel free to comment/upvote to attract greater attention from the devs!

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

No branches or pull requests

9 participants