X Tutup
The Wayback Machine - https://web.archive.org/web/20210106130917/https://github.com/python-xlib/python-xlib/issues/162
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

Extracting pointer coordinates from RawMotion event #162

Open
matanster opened this issue May 4, 2020 · 1 comment
Open

Extracting pointer coordinates from RawMotion event #162

matanster opened this issue May 4, 2020 · 1 comment

Comments

@matanster
Copy link

@matanster matanster commented May 4, 2020

Thanks for this wonderful library. I am writing a key and pointing device activity logger application for self-use to remind me of typing breaks and to eventually apply machine learning over my input device interaction patterns.

I find that unlike KeyPress and KeyRelease events, when listening for events of the root of the screen via Display().screen().root.xinput_select_events ― motion events only return if the cursor is inside the window where my code is running but not when it is over other windows. So to get all cursor events only raw motion events can be used.

Maybe that's because many/most applications remove motion events from the queue as they process them, whereas Key events aren't removed so often, or there's some other reason.

In any case, as opposed to this library's xinput.Motion event, the xinput.RawMotion event does not seem to come with an API for extracting the cursor position: we cannot event.data.root_x or event.data.event_x the event object coming from a RawMotion event.

Am I missing something obvious in this? I couldn't figure how to nail adding this API feature insofar but am happy to give it a go with some help. I did find a way to get the position by making an extra API call:

p = display.screen().root.query_pointer()
x_pos, y_pos = p.root_x, p.root_y
print(F"cursor position: ({x_pos}, {y_pos})")

However the numbers I am getting from this code snippet defer with those received on the event itself (and they also defer from those received on the (non-raw) Motion event.). So it's nice to have the equivalent API for the Raw events maybe. Or to learn how the coordinates supplied on the event defer from those received in querying the position while processing the event, maybe it is actually more accurate to believe the numbers coming back from the query.

@matanster
Copy link
Author

@matanster matanster commented May 5, 2020

Extracting the coordinates with qurey_pointer does work even though the semantics are then a little different (it's no longer the coordinates at the time of the event). However I'm wondering whether there's a particular set of reasons for RawMotion not formatting the data field for additional attributes which are available on the Motion event, like time and deviceid. These last attributes seem to be even more fundamental for many use cases. What am I missing?

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

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.
X Tutup