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

Mouse buttons keycodes? #261

Closed GhostValk closed 6 years ago

GhostValk commented 8 years ago

Sorry if it's a bit obvious the answer, but, what are the keycodes for the mouse buttons? I've tried button1, button2, button3, etc. unsuccesfully (are already implemented?)

graygilmore commented 8 years ago

I've gone through the source and have been unable to figure it out. I thought I could do something like:

{
  "profiles": [
    {
      "name": "Default profile",
      "selected": true,
      "simple_modifications": {
        "caps_lock": "escape"
      },
      "fn_function_keys": {
        // mac function stuff
      },
      "pointing_buttons": {
        "button4": "left"
      }
    }
  ]
}

I feel like I'm on the right path but can't quite filter through the source to figure out where it should be (v0.90.46).

mikefoley commented 8 years ago

I'd love to know as well. I miss my "back" key on my mouse!

GhostValk commented 8 years ago

Mouse usage is key for me, i got Dashboard and Expose binded to lateral buttons of the mouse =/

GhostValk commented 8 years ago

Any update here?

SaschaKrieg commented 8 years ago

I also want to know how to map a key to a mouse button click.

GhostValk commented 8 years ago

It would be good to have an answer from a dev, just to know if the mouse buttons can't currently be remapped or they can be but i'm not seeing the option :s

kurtlloyd commented 8 years ago

I'm also hoping that mapping of keys (e.g., R-command, R-option) to mouse keys (e.g., middle-click, right-click) will be added. That is critical for me. It worked great in the original Karabiner.

LunaticoCR commented 7 years ago

+1 on this. I used to have middle button mapped to left alt which in return through BetterTouchTools would help me drag windows easily. Hope a dev can chime in and shed some light.

AJLivine commented 7 years ago

+1. I understand tekezo is incredibly busy working on Karabiner, but I hope he finds some time to at least let us know if this is possible.

sunaj commented 7 years ago

+1 from me too - its one of primary features of Karabiner for me. Thanks for any time / energy spent on this aspect! :)

ngtjah commented 7 years ago

i'm a curious party

sanderboele commented 7 years ago

I would love to be able to map button4 to cmd-[

luispedrofonseca commented 7 years ago

+1

jhimanka commented 7 years ago

Now that MacOs provides capslock->control, the only reason to use Karabiner for me is to map left mouse button to left_control. A key issue.

patrickwelker commented 7 years ago

Regarding Mouse Buttons

I'd love to see this getting a higher priority, too. I can simulate Karabiner's other features with other software, or, my Ergodox EZ, but when it comes to my 6 button mouse, I'm out of luck so far. It's my main usage for Karabiner, along with my Trackball buttons.

Karabiner was - at least to my knowledge - the only app which could assign actions to all three different modes: click, double-click and hold.

I'd love to use this again:

piotrtobolski commented 7 years ago

Any news on this one? Simple mapping mouse buttons (3+) to keyboard or actions like previous/next space would be amazing. This was the only thing I used in original Karabiner.

oin commented 7 years ago

I got tired of waiting for this, so I wrote Clicker, a little app with no user interface that translates presses/releases of a key to presses/releases of the left mouse button. I've tested it for two months on OS X 10.11 and macOS 10.12, and it works flawlessly, even for complex mouse dragging operations. The only downside is that it doesn't work when a password field is focused (a security limitation of the Event Tap library).

Note that this doesn't translate mouse button presses to key presses or actions (even though one could make it work based on similar code).

Feel free to use it and modify it until Karabiner-Elements supports keyboard key to mouse button mapping.

LunaticoCR commented 7 years ago

@tekezo Are you planning on implementing mouse button mapping support at some stage? Thanks!

CorgFather commented 7 years ago

My Google searches for how to use the scroll drag on my Logitech mouse on my MBP pointed me to karabiner Elements (which I already had installed). Bummer that it's not working. I miss my Magic Mouse, but between it and the Magic Keyboard, I had gotten tennis elbow.

PayneJoe commented 7 years ago

still be waiting for it

nawkwan commented 7 years ago

I'd love to map [button4]/[button5] to [cmd]+<[eft_arrow]/[right_arrow], respectively.

jimmy-biznessapps commented 7 years ago

@nawkwan @PayneJoe @timbitzen @LunaticoCR @piotr-tobolski @pattulus @jhimanka @graygilmore @GhostValk etc --

Looks like as of Karabiner Elements 11.0, this can work if you don't mind json hacking:

(Note: This is just a snippet of the JSON, not the entire thing.)

            "complex_modifications": {
                "parameters": {
                    "basic.to_if_alone_timeout_milliseconds": 1000
                },
                "rules": [
                    {
                        "manipulators": [
                            {
                                "description": "Swipe down to move left one space",
                                "from": {
                                    "pointing_button": "button4",
                                    "modifiers": {
                                        "optional": [
                                            "any"
                                        ]
                                    }
                                },
                                "to": [
                                    {
                                        "key_code": "left_arrow",
                                        "modifiers": [
                                            "left_control"
                                        ]
                                    }
                                ],
                                "type": "basic"
                            },
                            {
                                "description": "Swipe up to move right one space",
                                "from": {
                                    "pointing_button": "button5",
                                    "modifiers": {
                                        "optional": [
                                            "any"
                                        ]
                                    }
                                },
                                "to": [
                                    {
                                        "key_code": "right_arrow",
                                        "modifiers": [
                                            "left_control"
                                        ]
                                    }
                                ],
                                "type": "basic"
                            }
                        ]
                    }
                ]
            },

I titled them "swipe down" and "swipe up" because that's how I trigger button4/button5 on my Microsoft Sculpt Comfort Mouse, AND you'll want to change "left_control" to "left_command" in both of these, but the above works for me. HUZZAH!

jimmy-biznessapps commented 7 years ago

...but the magic sauce, in both "complex" and simple rules, is to use "pointing_button" : "button4" to refer to button4, etc. These work if you put them in the JSON, but as far as I can tell, they don't work the same in the GUI (and show up as weird-looking entries there).

threescales commented 7 years ago

image

I think this function is cool !but it doesn't work in Karabiner-Element.

johnwilhite commented 7 years ago

@jimmy-biznessapps Your json isn't working for me, but if I look in the log I see: [2017-09-20 11:18:30.594] [info] [grabber] USB Optical Mouse (device_id:3) is ignored.

So It doesn't look like it's going to register any pointing events. Do you see your mouse under Devices? I only have my keyboard and the Apple Internal Keyboard / Trackpad.

jimmy-biznessapps commented 7 years ago

I do see my mouse under "devices." So that's probably a prerequisite for this to work.

graygilmore commented 7 years ago

@jimmy-biznessapps thanks for that. Unfortunately I have the similar error as above:

[2017-09-20 10:46:23.334] [info] [grabber] Razer DeathAdder 2013 (device_id:4) is ignored.

Oddly enough the mouse does appear under "Devices" in the GUI and I'm able to modify some of its values in the JSON config (for example, setting "is_keyboard": false on the mouse causes it to stop working entirely).

I'll have to return to this when I have a little more debugging time.

spamwax commented 7 years ago

@nawkwan My device is also ignored in Karabiner. For now to map M4 and M5 to a keystroke I am using ControllerMate app (free) with a custom made program. (Sample ControllerMate programe: M4M5.cmate.zip)

hanamiche commented 7 years ago

Hello! From the Karabiner-Elements 11.1.8(11.2.0?) mouse was supported!

Mouse button modifications has been added.

Mouse buttons 4, 5 and 6 are now available. I also moved in my environment. I could assign Button 4 to "Back". Thank you☺️

{ "description": "button4 β†’ [ + command", "from": { "pointing_button": "button4" }, "to": [ { "key_code": "close_bracket", "modifiers": [ "command" ] } ], "type": "basic" },

luispedrofonseca commented 7 years ago

@hanamiche Where do you put that? It didn't work for me if I put it under "Simple Modifications". Under "Complex Modifications" doesn't seem to have that format.

LunaticoCR commented 7 years ago

@luispedrofonseca I think you need to pull down a beta build. image

luispedrofonseca commented 7 years ago

@LunaticoCR Thanks, but yes, I have the latest beta. I can assign a mouse button to a key (like backspace) but I can't add the modifiers.

hanamiche commented 7 years ago

@luispedrofonseca Hello. I put this file under "Complex Modifications". Could you please use the json file? my setting json file. The path is "~/.config/karabiner/assets/complex_modifications/mouse.json". (I'm using Japanese keyboard, so I may need to modify "key_code".)

I also made a screen shot of the setting screen. screenshot

I hope to go well.

luispedrofonseca commented 7 years ago

@hanamiche That did it! Thanks for the explanation!

hanamiche commented 7 years ago

@luispedrofonseca Was good! Congratulations!!! πŸ˜‰

piotrtobolski commented 7 years ago

Works great. Now I can change spaces by tilting mouse wheel πŸ‘

ScottStevenson commented 7 years ago

@piotr-tobolski How did you reference the scrollwheel tilt input? I successfully got all my mouse buttons working, but after digging through the source code I still can't determine how to reference scrollwheel::LEFT and scrollwheel::RIGHT like in the previous version!

piotrtobolski commented 7 years ago

@ScottStevenson in my mouse (Logitech M325) tilting scrollwheel triggers mouse buttons 4 and 5. I am not using any 3rd party drivers or other software. I used Karabiner-EventViewer to check what events are triggered.

ScottStevenson commented 7 years ago

@piotr-tobolski Ah I see. I am using a Microsoft Sculpt mouse where tilting the scrollwheel outputs a "ScrollWheel" event in Karabiner-EventViewer with x and y coordinates/velocity.

After parsing through the source I am pretty sure this can't be referenced in the configuration at this time.

nawkwan commented 7 years ago

@jimmy-biznessapps @hanamiche The magic sauce of "pointing_button" didn't work for me. In fact, I've tried copying a slightly modified version (my_mouse.json) of hanamiche's mouse.json settings file under ~/.config/karabiner/assets/complex_modifications/mouse.json and it didn't map correctly. In fact, the rules didn't even show up under the Complex Modifications tab under KE's Preferences. KE Log

KE Complex Modifications tab

UPDATE: Please ignore these screenshots, they don't offer any insight. Instead, read about my new finings in my next reply.

hanamiche commented 7 years ago

@nawkwan Hello. I think that ignoring the mouse when looking at the log. Is karabiner-elements the latest beta version? Β  (In my environment, it is 11.1.11) Forgive me if I am wrong.

FatCash commented 7 years ago

@hanamiche Thank you very much, works great! Have been waiting for mouse feature forever!

nawkwan commented 7 years ago

@hanamiche Yes, I have updated to 11.1.11. The fact that the rules defined in your mouse.json don't even show up on the Complex Modifications tab suggests that something is wrong on my end. Since the last post, I've taken a closer look at the Log messages and compared it to the USB hardware on my MBP and have discovered where the conflict might be. But before I continue, I want to apologize for posting the previous screenshots of the Log and the Event Viewer, because they offer no insights.

This time around, I've disconnected all external USB devices from my MBP and restarted Karabiner-Elements. screenshot 2017-10-30 05 33 40 (The activities that occur starting from the arrow is when I first inserted the USB receiver for the mouse)

After KE started, I inserted the mouse USB Receiver directly into my MBP. Here you might be wondering why KE detected and registered ("grabbed") two USB receivers. Well, that's because I have two device entries with the same vendor_id and product_id for the two Logitech USB receivers -- one for the keyboard, and the other one for the mouse. (Please see lines 234 and 256 of my karabiner.json) This is probably causing some confusion for KE, because it's recognizing the receiver as both for the keyboard and the mouse.

Now, what I don't understand is why the VirtualHIDPointing device is being ignored.

Here's the Devices listing: screenshot 2017-10-30 07 44 19

Additionally, there are a few things I'd like to ask about putting settings json files under ~/.config/karabiner/assets/complex_modifications:

Take your mouse.json for example: 1) Which profile(s) are the rules defined in mouse.json applied to when you stick it under the /complex_modifications directory?

2) A follow up to 1): When you just stick that mouse.json file under the /complex_modifications directory, how does KE know what type of device are the rules for? There's no device-related information in mouse.json; you only have rules in there.

Can someone who has pointing_buttons working please share their karabiner.json file?

hanamiche commented 7 years ago

@nawkwan Hello, thank you for the information. My device list is the same Logitech. Even in my environment "USB Receiver" is the only one. I have not used the Logitech keyboard, so I unchecked it. 2017-10-31 10 20 05

It is necessary to enable json in ~/.config/karabiner/assets/complex_modifications from the GUI. It is merged into ~/.config/karabiner/karabiner.json and it becomes available. So I do not edit karabiner.json directly. You can activate it for each profile. (Will it be an answer to 1.?)

I will post the procedure. Karabiner-Elements Preferences -> Complex Modifications -> "Add rule" 2017-10-31 10 21 29

Since the rule list of the json file placed in ~/.config/karabiner/assets/complex_modifications is displayed Please Enable All or Enable. 2017-10-31 10 21 57

In the Enabled rules, the selected rule will be displayed and ready to use. (merged into ~/.config/karabiner/karabiner.json) 2017-10-31 10 22 13

I uploaded the ~/.config/karabiner/karabiner.json as it might be useful.

(I occasionally have Japanese but do not mind.πŸ˜‰)

I hope that it will work.

xbjconan commented 7 years ago

Hi @jimmy-biznessapps Do your json code have a modified function on the tilt and click of the scrollwheel on MS comfort sculpt mouse? If possible could you please share your json code with me/us?

Thank you

ultimate-s commented 6 years ago

Anybody have any idea why my Logitech G5 is ignored by Karabiner? It's not in the device list.

[2017-11-06 10:23:42.999] [info] [grabber] USB Gaming Mouse (device_id:2) is ignored.

[update] finally works on 11.2.0

        {
            "description": "Mouse button4 β†’ command+[",
            "manipulators": [
                {
                    "from": {
                        "pointing_button": "button4"
                    },
                    "to": [
                        {
                            "key_code": "open_bracket",
                            "modifiers": [
                                "command"
                            ]
                        }
                    ],
                    "conditions": [
                        {
                            "type": "frontmost_application_unless",
                            "bundle_identifiers": [
                                "^com\\.microsoft\\.rdc\\.osx"
                            ]
                        }
                    ],
                    "type": "basic"
                }
            ]
        }
jimmy-biznessapps commented 6 years ago

@xbjconan -- nope, I'm leaving that as-is. Sorry I can't help.

Also, turns out my other two MS Sculpt Comfort mice send different codes for the blue button... :|

rodneicouto commented 6 years ago

Can i remap Command + Left mouse click to Control + Left Arrow and Command + Right Mouse to Control + Right Arrow? Is something like this?

  ` "manipulators": [
            {
                "from": {
                    "pointing_button": "RIGHT",
                    "modifiers": {
                      "mandatory": [
                        "command"
                      ],
                      "optional": [
                        "any"
                      ]
                    }
                },
                 "to": [
                    {
                      "key_code": "right_arrow",
                      "modifiers": [
                        "control"
                      ]
                    }
                  ],
                "type": "basic"
            }
        ]`
MrDesjardins commented 6 years ago

For those who are looking to have the back button to their Microsoft Sculpt mouse on Mac 10.12 you can use the following configuration:

{
                        "manipulators": [
                            {
                                "description": "Mouse back",
                                "from": {
                                    "pointing_button": "button4"
                                },
                                "to": [
                                    {
                                        "key_code": "left_arrow",
                                        "modifiers": [
                                            "left_command"
                                        ]
                                    }
                                ],
                                "type": "basic"
                            }
                        ]
                    }

Inside /Users/YOURNAME/.config/karabiner/karabiner.json

Also, make sure that in the Karabiner preference you have checked Microsoft 2.4Ghz Transceiver v9.0 (Microsoft) with the "mouse" icon in the type column.

connorsadlervelo commented 6 years ago

Thanks very much for this thread, it helped me get my mouse4/5 buttons working as I like them. Karabiner seems to have some great functionality in this area. How do we "officially" share these excellent add ons?