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

Export of Mouse Button Raw Value Mapping for hidutil? #2795

Closed
winkelsdorf opened this issue Aug 19, 2021 · 13 comments
Closed

Export of Mouse Button Raw Value Mapping for hidutil? #2795

winkelsdorf opened this issue Aug 19, 2021 · 13 comments

Comments

@winkelsdorf
Copy link

winkelsdorf commented Aug 19, 2021

Hello,

I have a simple modification mapping and want to use this without Karabiner (as it's so simple). Is anybody aware of the raw values for hidutil?

image

See my post at AskDifferent here: https://apple.stackexchange.com/questions/425911/map-mouse-buttons-using-hidutil-how-to-find-keycodes?noredirect=1#comment605229_425911.

I identified the correct device:

hidutil list --matching '{"ProductID":0xb025,"VendorID":0x46d}'

My idea was to map using hidutil e.g. using https://hidutil-generator.netlify.app.

I am seeking for the correct key codes for HIDKeyboardModifierMappingSrc for Button 4 and 5 to Volume Inc/Dec for days, is anybody aware of them?

Is there a way to export them from Karabiner-Elements?

Edit: Volume Increment and Decrement apparently are 0xC000000EA and 0xC000000E9. Now searching for the scan code of Button 4 and 5.

@MuhammedZakir
Copy link

MuhammedZakir commented Aug 19, 2021

Edit: Volume Increment and Decrement apparently are 0xC000000EA and 0xC000000E9. Now searching for the scan code of Button 4 and 5.

If the values you posted are in correct order, then what I am saying is wrong.

From https://opensource.apple.com/source/IOHIDFamily/IOHIDFamily-315.7.16/IOHIDFamily/IOHIDUsageTables.h:

0xC is Consumer Page, and in it, 0xE9 & 0xEA are for kHIDUsage_Csmr_VolumeIncrement & kHIDUsage_Csmr_VolumeDecrement. So the syntax for keys for hidutil is probably <hid usage page><hid usage>. Just guessing.

In case this works, you can find Apple-specific codes in https://opensource.apple.com/source/IOHIDFamily/IOHIDFamily-700/IOHIDFamily/AppleHIDUsageTables.h.auto.html.

@winkelsdorf
Copy link
Author

@MuhammedZakir Thank you very much! Yes, the codes seem to be correct but I'm likely wrong about mapping Mouse Button Events - those are not sent the same way as Keyboard Events are. Looks like I need to write a small utility using CGEvent.tapCreate. I'll keep this thread updated.

@winkelsdorf
Copy link
Author

Closing this for now, seems like it's not worth the work to reinvent the wheel Karabiner provides

@MuhammedZakir
Copy link

If you are going to use CGEvent, you may as well use HammerSpoon.

@winkelsdorf
Copy link
Author

@MuhammedZakir Thanks for the suggestion! In the meantime I wrote my own daemon: https://github.com/winkelsdorf/MouseEnhancer/blob/main/MouseEnhancer/main.swift.

@MuhammedZakir
Copy link

[...] So the syntax for keys for hidutil is probably <hid usage page><hid usage>. Just guessing.

Found the correct way to get the key code from dnicolson/Bluetooth-Keyboard-Enhancer#5:

HIDUsagePage << 32 | HIDUsage

@winkelsdorf
Copy link
Author

winkelsdorf commented Aug 20, 2021

Excellent find @MuhammedZakir, many thanks!

I was off by << 32, so the codes are correct:

0xC000000EA // Volume decrement
0xC000000E9 // Volume Increment

Which fits https://developer.apple.com/documentation/iokit/1592162-anonymous/khidusage_csmr_volumedecrement, and https://developer.apple.com/documentation/iokit/1592162-anonymous/khidusage_csmr_volumeincrement.

But this still leaves the problem: A mouse sidebutton has no standard code. Should be UsagePage 1 as reported by hidutil, but the event is CGEventMask(1 << CGEventType.otherMouseDown.rawValue) with a sent event.getIntegerValueField(.mouseEventButtonNumber) for the buttons 3 and 4. The latter defined as case mouseEventButtonNumber = 3 as UInt32.

Even if I can reach otherMouseDown which is defined by Apple as case otherMouseDown = 25 as UInt32, there seems to be no way to map the payload of the pressed button number to hidutil. At least as far as I can see.

It might be 1 << 32 | 0x19 (for dec 25) but still lacks mouseEventButtonNumber (0x03) and the button number itself (0x03 and 0x04). Need to investigate if that's possible to address directly.

@MuhammedZakir
Copy link

@winkelsdorf
Copy link
Author

@MuhammedZakir I think Button Page 0x09 is for Buttons of Game Controllers and others. Mouse should be 0x01.

@MuhammedZakir
Copy link

@MuhammedZakir I think Button Page 0x09 is for Buttons of Game Controllers and others.

This makes me think otherwise (above Button Page enum):

/* The Button page is the first place an application should look for user selection controls. System graphical user interfaces typically employ a pointer and a set of hierarchical selectors to select, move and otherwise manipulate their environment. For these purposes the following assignment of significance can be applied to the Button usages: */
/* ¥ Button 1, Primary Button. Used for object selecting, dragging, and double click activation. On MacOS, this is the only button. Microsoft operating systems call this a logical left button, because it */
/* is not necessarily physically located on the left of the pointing device. */
/* ¥ Button 2, Secondary Button. Used by newer graphical user interfaces to browse object properties. Exposed by systems to applications that typically assign application-specific functionality. */
/* ¥ Button 3, Tertiary Button. Optional control. Exposed to applications, but seldom assigned functionality due to prevalence of two- and one-button devices. */
/* ¥ Buttons 4 -55. As the button number increases, its significance as a selector decreases. */
/* In many ways the assignment of button numbers is similar to the assignment of Effort in Physical descriptors. Button 1 would be used to define the button a finger rests on when the hand is in the Òat restÓ position, that is, virtually no effort is required by the user to activate the button. Button values increment as the finger has to stretch to reach a control. See Section 6.2.3, ÒPhysical Descriptors,Ó in the HID Specification for methods of further qualifying buttons. */

Mouse should be 0x01.

0x01 is GenericDesktop usage page. It is not specific to mouse.

@winkelsdorf
Copy link
Author

Sounds reasonable, I'll give it a try. I am just wondering if that doesn't depend on the device itself reporting to use a Usage Page of 0x01.

hidutil list gives me the following for the Logitech Anywhere MX 3:

Devices:
VendorID ProductID LocationID UsagePage Usage RegistryID  Transport            Class                      Product                            UserClass Built-In 
0x46d    0xb025    0xaa3c803e 1         2     0x10000341a Bluetooth Low Energy IOHIDResource              MX Anywhere 3                      (null)    (null)  

@lcmen
Copy link

lcmen commented Jul 13, 2022

@winkelsdorf where you able to find id codes for mouse buttons that work with hidutil?

@winkelsdorf
Copy link
Author

@lcmen Not beside the side buttons, which I used here https://github.com/winkelsdorf/MouseEnhancer/blob/08751491a5c4a9380ac372bb0a93ebc39530f757/MouseEnhancer/main.swift#L42. But as this was enough for me (control volume from side buttons), I stopped searching for more.

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

No branches or pull requests

3 participants