karabiner

Mouse button as modifier


I would like to use a button on the mouse as a modifier for when I click another button.

I found this https://github.com/tekezo/Karabiner-Elements/issues/1223 but it was closed due to inactivity.

I have tried to use simultaneous in the from definition but it does not work.

{
    "description": "Maps button6 and button3 to close action (cmd-w)",
    "manipulators": [
        {
            "from": {
                "modifiers": [
                    {
                        "pointing_button": "button6"
                    }
                ],
                "pointing_button": "button3"
            },
            "to": [
                {
                    "key_code": "w",
                    "modifiers": [
                        "left_command"
                    ],
                    "repeat": false
                }
            ],
            "type": "basic"
        }
    ]
}

Any ideas how to do this?

edit:

I ended up doing it like this:

{
    "description": "Maps button2 to close action (cmd-w) when button6 is pressed",
    "manipulators": [
        {
            "conditions": [
                {
                    "type": "variable_if",
                    "name": "button6_down",
                    "value": 1
                }
            ],
            "from": {
                "pointing_button": "button2"
            },
            "to": [
                {
                    "key_code": "w",
                    "modifiers": [
                        "left_command"
                    ],
                    "repeat": false
                }
            ],
            "type": "basic"
        }
    ]
},
{
    "description": "Maps button6 to variable",
    "manipulators": [
        {
            "from": {
                "pointing_button": "button6"
            },
            "to": [
                {

                    "set_variable": {
                        "name": "button6_down",
                        "value": 1
                    }
                }
            ],
            "to_after_key_up": [
                {

                    "set_variable": {
                        "name": "button6_down",
                        "value": 0
                    }
                }
            ],
            "type": "basic"
        }
    ]
}

The to_after_key_up apparently works for mouse buttons as well


Solution

  • I think that "simultaneous" still expects to find two "down events" at the same time, which I doubt that 2 mouse buttons can be – but I may err in this.
    [EDIT: EventViewer made me realise that 2 mouse buttons CAN be pressed simultaneously. But I use a mouse with 2 buttons; "button1" will not be remapped by K-E, so I can't test your case.]

    If 2 mouse buttons really are NOT recognised "simultaneous"ly, you might try this:

    Define a variable "mb3_down" that's set to "1" by button_3 while, in a a second manipulator, button_6 (if "mb3_down" = 1) should first invoke Cmd-W and afterwards reset "mb3_down" to "0". I believe this should work.

    I'd recommend though that you add a "to_delayed_action" that –let's say after 2 seconds– resets "mb3_down" in any case (otherwise next time you use button_6 on its own it might close some window unexpectedly).