pqrs-org / Karabiner-Elements

Karabiner-Elements is a powerful utility for keyboard customization on macOS Sierra (10.12) or later.
https://pqrs.org/osx/karabiner/
The Unlicense
18.8k stars 838 forks source link

Allow complex modifications per device in the GUI #1073

Open rggjan opened 7 years ago

rggjan commented 7 years ago

There are some complex modifications (rules) I would like to enable only on my external keyboard. It would be great if this could be enabled, the same way as the simple modifications and Function keys can be set individually per device.

weibeld commented 7 years ago

I need exactly the same thing. Now, I have to disable all the other devices completely in the "Devices" tab in order to prevent that my rules apply to these devices also. I should be possible to restrict complex rules to individual devices.

weibeld commented 7 years ago

It's a workaround, but not exactly the same thing. With this solution, it's not possible to have different complex modifications for different devices at the same time (i.e. in the same profile).

I think with the old Karabiner this was possible. You just defined a set of applications and a set of devices, and then you could restrict each rule to an application and a device. With the new Karabiner-Elements, each complex modification rule can be restricted to an application, but not to a device.

2017-11-03 9:04 GMT+01:00 nguyenhimself notifications@github.com:

Isn't that how 'Profiles' already works currently? I have 4 sets of configs and complex rules on my machine.

In fact, thanks to an automatically-enabled macro in Keyboard Maestro, I don't even need to do anything. Just plug in an external keyboard and the correct profile is selected.

[image: screen shot 2017-11-03 at 3 00 27 pm] https://user-images.githubusercontent.com/482270/32364510-d7f6b25a-c0a7-11e7-8dad-ecf31a0d4bfa.png

[image: screen shot 2017-11-03 at 3 03 13 pm] https://user-images.githubusercontent.com/482270/32364557-243ae5e6-c0a8-11e7-91ec-a30c2cbef0c4.png

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/tekezo/Karabiner-Elements/issues/1073#issuecomment-341640964, or mute the thread https://github.com/notifications/unsubscribe-auth/ACSQMG3AOt1jxKcEXbNGhcne18ZMFejfks5syskcgaJpZM4QKyGx .

weibeld commented 7 years ago

I just saw that it is actually possible with the "device_if" condition in complex modification rules, as demonstrated here (referenced from #979).

So, I think this issue can be closed.

rggjan commented 6 years ago

@weibeld Great to know there is a way to do it. However, I still think this is not very user friendly, especially when importing rules from the Internet: These would have to be downloaded, manually edited by hand and then reimported into Karabiner-Elements again, right? Not something the average user can do when he imports some predefined rules from others...

weibeld commented 6 years ago

Yes, basically. When you import a rule from the Internet through the Karabiner-Elements GUI, it gets saved as a JSON file in the following directory (this is also where you save your own rules):

~/.config/karabiner/assets/complex_modifications

There you can edit it by hand, and then you can enable the rule in the GUI (if you already enabled it before, then you have to remove the rule and add it again in order to reload the changes).

I think too it's not very user-friendly. There should be a section in the UI where you can declare devices (by their vendor ID and product ID) and a section where you can declare apps (by their app ID). And then there should be a function in the GUI to freely add devices and/or apps to individual rules, to restrict the rules to these devices/apps.

Also, now you have to repeat each device/app condition for each keystroke inside a rule, which I think is unnecessary too. It would be enough to set device and app conditions for an entire rule as a whole.

rggjan commented 6 years ago

Thanks for the explanation! I agree it would be better to be able to do this in the GUI. It is already possible for the simple rules, so this shouldn't be too hard to implement, or am I wrong?

weibeld commented 6 years ago

I'm not familiar with the source code, I think it would require some substantial changes, but certainly it's not impossible.

I also think JSON is not a good idea for configuration files that are supposed to be edited by hand. That's one of the first things I would change too.

stale[bot] commented 6 years ago

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.

rggjan commented 6 years ago

Still interested in this, please don't close it

FuegoFro commented 6 years ago

This looks related to (and maybe a dupe of) https://github.com/tekezo/Karabiner-Elements/issues/979?

rggjan commented 6 years ago

No, #979 is still about modification of the json file. I would like to see it in the UI instead... On Wed, 7 Mar 2018 at 01:15, Danny Weinberg notifications@github.com wrote:

This looks related to (and maybe a dupe of) #979 https://github.com/tekezo/Karabiner-Elements/issues/979?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/tekezo/Karabiner-Elements/issues/1073#issuecomment-370976266, or mute the thread https://github.com/notifications/unsubscribe-auth/AAH2Ks1V44l5kMsn82HIw5V0ijgH8OK3ks5tbyaTgaJpZM4QKyGx .

stale[bot] commented 6 years ago

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.

rggjan commented 6 years ago

Still interested in this, please don't close...

stale[bot] commented 6 years ago

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.

rggjan commented 6 years ago

Still interested in this, please don't close...

stale[bot] commented 6 years ago

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.

rggjan commented 6 years ago

Still interested in this, please don't close...

stale[bot] commented 6 years ago

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.

rggjan commented 6 years ago

Maybe I should write a bot which keeps replying to the other bot that I'm still interested in this feature... 😜

stale[bot] commented 5 years ago

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.

rggjan commented 5 years ago

Still interested in this, please don't close...

JordanPeterson commented 5 years ago

Also interested please don't close

jayache80 commented 5 years ago

Very interested in this

stale[bot] commented 5 years ago

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.

jayache80 commented 5 years ago

Still interested in this

petergaultney commented 5 years ago

I'd really like to see this as well, and am glad to see there's an issue for it.

RexYuan commented 5 years ago

interested as well. Hope somebody figure this out somehow

idvorkin commented 5 years ago

This is already implemented as the device_if condition (can someone copy to the top). @rggjan can you update your question description with the answer - Thanks!!

See:

     "conditions": [
        {
          "type": "device_if",
          "identifiers": [
            {
              "vendor_id": 1278,
              "product_id": 515
            }
          ]
        }
      ],
rggjan commented 5 years ago

Hi @idvorkin. Thanks! However, I'm specifically asking for making this possible via UI (eg download and activate a predefined complex modification for only one device vi UI, without messing with config files). Sorry for not being clear about that.

stale[bot] commented 5 years ago

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.

jayache80 commented 5 years ago

I am also interested in a UI method of setting this. I don’t want to go update a bunch of .json files every time I plug a different keyboard in

stale[bot] commented 5 years ago

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.

rggjan commented 5 years ago

This issue has been automatically marked as not stale because @rggjan is still interested in this. Thank you for your understanding.

stale[bot] commented 4 years ago

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.

rggjan commented 4 years ago

This issue has been automatically marked as not stale because @rggjan is still interested in this. Thank you for your understanding.

stale[bot] commented 4 years ago

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.

rggjan commented 4 years ago

This issue has been automatically marked as not stale because @rggjan is still interested in this. Thank you for your understanding.

stale[bot] commented 4 years ago

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.

mifopen commented 4 years ago

Ok, bot. Could you close this issue one more time next month, please?

dtgay commented 4 years ago

I also need this functionality. My external keyboard is set up beautifully but when using the built-in keyboard I need stuff like caps+hjkl -> arrow keys.

Keeping the dream alive.

AnthonyJS commented 4 years ago

I just saw that it is actually possible with the "device_if" condition in complex modification rules, as demonstrated here (referenced from #979).

So, I think this issue can be closed.

The link here is not found anymore. Could some please post an example using "device_if"?

--- Edit ---

Worked out how to do it with complex modifications:

Here's how to swap the " and the @ on a specific external keyboard only

"complex_modifications": {
  "parameters": {
      "basic.simultaneous_threshold_milliseconds": 50,
      "basic.to_delayed_action_delay_milliseconds": 500,
      "basic.to_if_alone_timeout_milliseconds": 1000,
      "basic.to_if_held_down_threshold_milliseconds": 500,
      "mouse_motion_to_scroll.speed": 100
  },
  "rules": [
      {
          "description": "At to quote",
          "manipulators": [
              {   
                  "conditions": [
                      {
                          "type": "device_if",
                          "identifiers": [
                          {
                              "vendor_id": 1241,
                              "product_id": 17733
                          }
                          ]
                      }
                  ],
                  "from": {
                      "key_code": "2",
                      "modifiers": {
                          "mandatory": [
                              "shift"
                          ]
                      }
                  },
                  "to": [
                      {
                          "key_code": "quote",
                          "modifiers": ["shift"]
                      }
                  ],
                  "type": "basic"
              }
          ]
      },
      {
          "description": "Quote to at",
          "manipulators": [
              {
                  "conditions": [
                      {
                          "type": "device_if",
                          "identifiers": [
                          {
                              "vendor_id": 1241,
                              "product_id": 17733
                          }
                          ]
                      }
                  ],
                  "from": {
                      "key_code": "quote",
                      "modifiers": {
                          "mandatory": [
                              "shift"
                          ]
                      }
                  },
                  "to": [
                      {
                          "key_code": "2",
                          "modifiers": ["shift"]
                      }
                  ],
                  "type": "basic"
              }
          ]
      }
  ]
},
blank0ken commented 4 years ago

I just saw that it is actually possible with the "device_if" condition in complex modification rules, as demonstrated here (referenced from #979). So, I think this issue can be closed.

The link here is not found anymore. Could some please post an example using "device_if"?

--- Edit ---

Worked out how to do it with complex modifications:

Here's how to swap the " and the @ on a specific external keyboard only

"complex_modifications": {
  "parameters": {
      "basic.simultaneous_threshold_milliseconds": 50,
      "basic.to_delayed_action_delay_milliseconds": 500,
      "basic.to_if_alone_timeout_milliseconds": 1000,
      "basic.to_if_held_down_threshold_milliseconds": 500,
      "mouse_motion_to_scroll.speed": 100
  },
  "rules": [
      {
          "description": "At to quote",
          "manipulators": [
              {   
                  "conditions": [
                      {
                          "type": "device_if",
                          "identifiers": [
                          {
                              "vendor_id": 1241,
                              "product_id": 17733
                          }
                          ]
                      }
                  ],
                  "from": {
                      "key_code": "2",
                      "modifiers": {
                          "mandatory": [
                              "shift"
                          ]
                      }
                  },
                  "to": [
                      {
                          "key_code": "quote",
                          "modifiers": ["shift"]
                      }
                  ],
                  "type": "basic"
              }
          ]
      },
      {
          "description": "Quote to at",
          "manipulators": [
              {
                  "conditions": [
                      {
                          "type": "device_if",
                          "identifiers": [
                          {
                              "vendor_id": 1241,
                              "product_id": 17733
                          }
                          ]
                      }
                  ],
                  "from": {
                      "key_code": "quote",
                      "modifiers": {
                          "mandatory": [
                              "shift"
                          ]
                      }
                  },
                  "to": [
                      {
                          "key_code": "2",
                          "modifiers": ["shift"]
                      }
                  ],
                  "type": "basic"
              }
          ]
      }
  ]
},

I got the Apple Internal Keyboard's product_id and vendor_id in hexadecimal, and I transformed to decimalism, but It doesn't seem to work.

{
  "title": "Escape Key",
  "rules": [
    {
      "description": "Escape key (grave_accent_and_tilde as Escape and fn + grave_accent_and_tilde as grave_accent_and_tilde)",
      "manipulators": [
        {
          "type": "basic",
          "conditions": [
            {
              "type": "device_if",
              "identifiers": [
                {
                  "vendor_id": 1452,
                  "product_id": 635
                }
              ]
            }
          ],
          "from": {
            "key_code": "grave_accent_and_tilde",
            "modifiers": {
              "mandatory": [
                "fn"
              ],
              "optional": [
                "caps_lock"
              ]
            }
          },
          "to": [
            {
              "key_code": "grave_accent_and_tilde"
            }
          ]
        },
        {
          "type": "basic",
          "from": {
            "key_code": "grave_accent_and_tilde"
          },
          "to": [
            {
              "key_code": "escape"
            }
          ]
        }
      ]
    }
  ]
}
stale[bot] commented 4 years ago

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.

rggjan commented 4 years ago

This issue has been automatically marked as not stale because @rggjan is still interested in this. Thank you for your understanding.

MuhammedZakir commented 4 years ago

https://karabiner-elements.pqrs.org/docs/json/complex-modifications-manipulator-definition/conditions/device/

rggjan commented 4 years ago

https://karabiner-elements.pqrs.org/docs/json/complex-modifications-manipulator-definition/conditions/device/

https://github.com/pqrs-org/Karabiner-Elements/issues/1073#issuecomment-342090453

MuhammedZakir commented 4 years ago

#1073 (comment)

Ah!


https://github.com/pqrs-org/Karabiner-Elements/issues/1073#issuecomment-342208484:

--snip-- I think too it's not very user-friendly. There should be a section in the UI where you can declare devices (by their vendor ID and product ID) and a section where you can declare apps (by their app ID). And then there should be a function in the GUI to freely add devices and/or apps to individual rules, to restrict the rules to these devices/apps. --snip--

+1. This would be great!

ajanian commented 3 years ago

for anyone who comes across this in the future - I have a satechi bluetooth keypad and a Matias tactile pro keyboard. Both are showing as the same vendor (apple) and product even though they aren't. I think that is because they have a generic apple driver.

                        "product_id": 544,
                        "vendor_id": 1452

In order to differentiate the keys coming from the keypad vs the keyboard I had to use the location_id as a param to device_if. location_id isn't permanent so I have a daemon that runs and modifies the json to set the location_id to the new location_id of the keypad if it changes.

MuhammedZakir commented 3 years ago

**--snip-- location_id isn't permanent so I have a daemon that runs and modifies the json to set the location_id to the new location_id of the keypad if it changes.

If you don't mind, can you share the code?

ajanian commented 3 years ago

@MuhammedZakir - will post code tomorrow when I'm back at my desk. Need to clean it up a bit and factor it out to be standalone