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

Getting raw multitouch (trackpad) events on Darwin #513

Open
adamberenzweig opened this issue Nov 10, 2022 · 1 comment
Open

Getting raw multitouch (trackpad) events on Darwin #513

adamberenzweig opened this issue Nov 10, 2022 · 1 comment

Comments

@adamberenzweig
Copy link

Hello,

Apologies for the platform-specific question, but this seems like a good place to find knowledgable folks.

I was looking into extending pynput to get multitouch events from a trackpad on MacOS. I'm following the pattern of the mouse and keyboard listeners, and I feel like I'm close but I hit a stumbling block.

I can get a stream of NSEvent that seem to represent the touches. But in order to get the actual touch data from there (e.g., location on the trackpad), you need to get NSTouch objects. I tried:

touches = ns_event.allTouches()
print(touches) # --> empty

touches = ns_event.touchesMatchingPhase_inView_(Quartz.NSTouchPhaseAny, None)
print(touches) # --> still empty

I put a complete example here: https://gist.github.com/adamberenzweig/25d71d97ca7c1510fefd5a662791f576

One possibility is that the OS won't attach touch events if the application hasn't called the NSView method setAcceptsTouchEvents, which the docs mention. However:

  1. I don't know if it's possible to get an NSView for a command-line python script. I guess I'm hoping I could get a view associated w/ the Terminal window. I've tried NSapplication.sharedApplication().windows() with no luck.
  2. This post suggests that passing Nil as the view param of touchesMatchingPhase_inView_ should work. But we might need a view that is a firstResponder -- which again hits the problem that we don't have a view.

Has anyone gone down this path before?
Thanks!

@moses-palmer
Copy link
Owner

moses-palmer commented Nov 29, 2022

Thank you for your report.

Unfortunately, I no longer have access to a macOS system, so I cannot help you. I would very much appreciate your contribution if you manage to get to work however.

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

2 participants