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

eventtap: Possible to know the keyboard that produced the event? #1083

Closed
wincent opened this issue Nov 17, 2016 · 9 comments
Closed

eventtap: Possible to know the keyboard that produced the event? #1083

wincent opened this issue Nov 17, 2016 · 9 comments

Comments

@wincent
Copy link

wincent commented Nov 17, 2016

Use case: three "keyboards", one of which is actually a YubiKey (the others are the laptop built-in keyboard and a standard USB external keyboard).

The YubiKey has some oddities, including sending the wrong keycodes when the system layout is set to Colemak. I'd like to be able to remap (fix) those keys using hs.eventtap, but specifically for the YubiKey, leaving the others alone.

Alas, there doesn't seem to be anything in hs.eventtap.event.properties that I can use to distinguish the keyboards. For example, keyboardEventKeyboardType returns 43 for the laptop, but 40 for both the USB keybord and the YubiKey. I've looked through the raw event data and can't find anything there either.

Is it possible to obtain event source information, and can it be exposed to Hammerspoon?

@asmagill
Copy link
Member

With what we have now, no, I don't believe it is possible... and an initial search on the Internet suggests much the same... by the time the Quartz Event Services hands things off to an application, there doesn't seem to be a way to get a vendor ID for a key event... for a tablet, yes, but not for a key.

If the YubiKey isn't something that you have plugged in regularly, you could set up a usb watcher with hs.usb.watcher and switch back and forth with that, but... at least for now that's the best I can suggest.

If anyone has any other thoughts, I'd like to be proven wrong... I have a couple of USB keyboards I don't like the layout of and wouldn't mind being able to change on the fly myself, but in a selective way.

@wincent
Copy link
Author

wincent commented Nov 17, 2016

If the YubiKey isn't something that you have plugged in regularly

Unfortunately it is; it's this tiny little thing that sits in there all the time:

img_20160516_104557-e1463352743583-300x300

I'm just going to have to get used to switching layouts (probably set up a binding to make it fast).

@cmsj
Copy link
Member

cmsj commented Nov 18, 2016

(I'm going to close this out because I don't think there is any work to be done in Hammerspoon. Please re-open if you disagree!)

@cmsj cmsj closed this as completed Nov 18, 2016
@asmagill
Copy link
Member

@wincent, no idea if this might help, but you might check the eventSourceUserData property of the keyboard event with event:getProperty(hs.eventtap.event.properties.eventSourceUserData)... Apple's documentation mentions that this can be used for a vendor id with some devices... no idea if YubiKey does this or not, but so far it's the only lead I've been able to come up with.

@wincent
Copy link
Author

wincent commented Dec 27, 2016

Yeah, I already checked that one out @asmagill. In the end, I ended up working around the issue by getting a newer YubiKey that allows you to reprogram the scanmap, which I did (for Colemak) with:

ykpersonalize -S 06050a0e08170b0f1c11180d16090c1986858a8e88978b8f9c91988d96898c99271e1f202122232425262b9e28

@matthewgrossman
Copy link

Now that we're a few years later, anyone have other ideas about how to best detect which device a hs.eventtap.event came from? My usecase is that I have two mice, and depending on which one I have plugged in I may/may not want to :start() an event listener.

My usecase is thankfully simpler in that I can enable/disable the event listener via usb watchers. However, I figured I'd check this method first to see if I can escape-early if the event came from the wrong mouse and always have the listener active instead.

@goldlil
Copy link

goldlil commented Jan 5, 2023

Any solution for this in 2023. I have one trackball that I want to use exclusively for scrolling. I have implemented this using hs.eventtap.event.types.mouseMoved but after that every my other mouse and trackpad are unusable and all they do is scrolling. Is there any way to make this work exclusively for single device? Karabiner has vendor_id eg that can be used to distinguish between devices.

@cmsj
Copy link
Member

cmsj commented Jan 9, 2023

Any solution for this in 2023. I have one trackball that I want to use exclusively for scrolling. I have implemented this using hs.eventtap.event.types.mouseMoved but after that every my other mouse and trackpad are unusable and all they do is scrolling. Is there any way to make this work exclusively for single device? Karabiner has vendor_id eg that can be used to distinguish between devices.

I don't think any of Apple's APIs for this have changed, unfortunately. I would suggest doing it with Karabiner, since it has access to the lower level device info.

@goldlil
Copy link

goldlil commented Jan 23, 2023

I have tried to make it with karabiner, # but its mouse_motion_to_scroll is too rigid. For Eg, I can't make acceleration custom, or I can't make it to scroll down using horizontal instead of vertical mouse movement. Is there any other tool I can use to achieve this? I have tried steermouse and usb overdrive, but it didn't work. Is there any way to, for example, decorate mouse inputs with additional info via some other software or some c++ scripts so hammerspoon can distinguish between devices.

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

5 participants