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.79k stars 838 forks source link

Complex modification with pointing_button and mandatory modifier is not working #3006

Open dciesielkiewicz opened 2 years ago

dciesielkiewicz commented 2 years ago

Hi, I'm using Intel MacBook with latest version of Mac OS Monterey with Karabiner v14.3.0 and I couldn't make mouse button complex modification working properly.

This is how my modification looks like:

{
  "title": "Switch desktop with command and mouse button4,5",
  "rules": [
    {
      "description": "Maps command and button 5 to left desktop switch, 4 to right desktop switch",
      "manipulators": [
        {
          "type": "basic",
          "from": {
            "pointing_button": "button5",
            "modifiers": {
              "mandatory": ["command"]
            }
          },
          "to": [
            {
              "key_code": "left_arrow",
              "modifiers": "left_control"
            }
          ]
        },
        {
          "from": {
            "pointing_button": "button4",
            "modifiers": {
              "mandatory": ["command"]
            }
          },
          "to": [
            {
              "key_code": "right_arrow",
              "modifiers": "left_control"
            }
          ]
        }
      ]
    }
  ]
}

I have "Modify events from this device" enabled and modification works perfectly fine, when modifiers is missing

"modifiers": {
  "mandatory": ["command"]
}

Does anyone have an idea, what could be wrong, here?

Bashwy commented 2 years ago

you are missing the "type": "basic" from the second manipulator that's why it doesn't work when a modifier is there

dciesielkiewicz commented 2 years ago

@Bashwy Thanks for your feedback ;-) In the meantime I've changed config to the proper one, but it still doesn't work for me:

{
  "title": "Go back and forward with command and mouse buttons 4,5",
  "rules": [
    {
      "description": "Maps command + button 5 to go back, 4 to go forward",
      "manipulators": [
        {
          "type": "basic",
          "from": {
            "pointing_button": "button5",
            "modifiers": "command"
          },
          "to": [
            {
              "key_code": "open_bracket",
              "modifiers": "left_command"
            }
          ]
        },
        {
          "type": "basic",
          "from": {
            "pointing_button": "button4",
            "modifiers": "command"
          },
          "to": [
            {
              "key_code": "close_bracket",
              "modifiers": "left_command"
            }
          ]
        }
      ]
    }
  ]
}
Bashwy commented 2 years ago

ahh yes the key codes for "[" and "]" are actually "open_bracket" and "close_bracket". you can find the names of all keys with the Karabiner-EventViewer app

dciesielkiewicz commented 2 years ago

@Bashwy I updated the json above and after replacing [ and ] with open_bracket and close_bracket it still doesn't work. Instead of simulating command and a bracket, it still treats it as a standard command and mouse button.

Zrzut ekranu 2022-04-21 o 14 36 01

The thing is completely opposite when I drop modifier "modifiers": "command". Then it works properly

{
  "title": "Go back and forward with command and mouse buttons 4,5",
  "rules": [
    {
      "description": "Maps command + button 5 to go back, 4 to go forward",
      "manipulators": [
        {
          "type": "basic",
          "from": {
            "pointing_button": "button5"
          },
          "to": [
            {
              "key_code": "open_bracket",
              "modifiers": "left_command"
            }
          ]
        },
        {
          "type": "basic",
          "from": {
            "pointing_button": "button4"
          },
          "to": [
            {
              "key_code": "close_bracket",
              "modifiers": "left_command"
            }
          ]
        }
      ]
    }
  ]
}
Zrzut ekranu 2022-04-21 o 14 46 43

Also I tested it will all the other complex modifications dropped to be sure that nothing else overrides my config.

Bashwy commented 2 years ago

there shouldn't be a title before the rules also you forgot the brackets for the modifiers { "description": "Maps command + button 5 to go back, 4 to go forward", "manipulators": [ { "from": { "modifiers": { "mandatory": [ "left_command" ], "optional": [ "caps_lock" ] }, "pointing_button": "button5" }, "to": [ { "key_code": "close_bracket", "modifiers": [ "left_command" ] } ], "type": "basic" }, { "from": { "modifiers": { "mandatory": [ "left_command" ], "optional": [ "caps_lock" ] }, "pointing_button": "button4" }, "to": [ { "key_code": "open_bracket", "modifiers": [ "left_command" ] } ], "type": "basic" } ] } sorry it looks weird karabiner should clean it up to look normal but this should work

dciesielkiewicz commented 2 years ago

@Bashwy When I've pasted your JSON to the file in ~/.config/karabiner/assets/complex_modifications/{fileName}.json, it didn't even appear after clicking Add rule.

Zrzut ekranu 2022-04-21 o 17 21 37

After formatting it and wrapping in { "rules": [...your-stuff-here] } it still didn't work for me.

{
  "rules": [
    {
      "description": "Maps command + button 5 to go back, 4 to go forward",
      "manipulators": [
        {
          "from": {
            "modifiers": {
              "mandatory": [
                "left_command"
              ],
              "optional": [
                "caps_lock"
              ]
            },
            "pointing_button": "button5"
          },
          "to": [
            {
              "key_code": "close_bracket",
              "modifiers": [
                "left_command"
              ]
            }
          ],
          "type": "basic"
        },
        {
          "from": {
            "modifiers": {
              "mandatory": [
                "left_command"
              ],
              "optional": [
                "caps_lock"
              ]
            },
            "pointing_button": "button4"
          },
          "to": [
            {
              "key_code": "open_bracket",
              "modifiers": [
                "left_command"
              ]
            }
          ],
          "type": "basic"
        }
      ]
    }
  ]
}
Zrzut ekranu 2022-04-21 o 17 25 26
Bashwy commented 2 years ago

after pasting the code directly into the file can you see the name next to your other complex mods? if so you might need to let karabiner manipulate the mouse in the devices tab Screenshot 2022-04-21 at 5 02 16 pm

MuhammedZakir commented 2 years ago

The thing is completely opposite when I drop modifier "modifiers": "command". Then it works properly

IIRC, from Catalina onwards, there was a bug which prevented remapping modfier+mouse_click combo. ~I suspect this bug has not been fixed or has been reintroduced.~ (Edit: it's working. See the next post.)


after pasting the code directly into the file can you see the name next to your other complex mods?

@dciesielkiewicz wants to save complex modifications in ~/.config/karabiner/assets/complex_modifications/ and import it from KE, rather than to directly add rules to karabiner.json file. That's why, there is title and rules in the config they posted.

MuhammedZakir commented 2 years ago

@dciesielkiewicz: I have tested mapping control+button3 to control+left_arrow and it's working for me. I suspect you have not enabled input modification for the mouse and keyboards. Can you post a screenshot of "Devices" tab?

Software versions: KE: 14.4.0, macOS: 12.0.1

Config used: note: I typed this, so there might be syntax errors. See "Log" tab after adding this config to check if there is any error.

{
  "title": "Test: mouse button with modifier",
  "rules": [{
    "description": "control+button3 -> control+left_arrow",
    "manipulators": [{
      "type": "basic",
      "from": {
        "pointing_button": "button3",
        "modifiers": {
          "mandatory": ["command"]
        }
      },
      "to": [{
        "key_code": "left_arrow",
        "modifiers": ["control"]
      }]
    }]
  }]
}