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

XTEST fake input API #178

Open
matanster opened this issue Sep 28, 2020 · 1 comment
Open

XTEST fake input API #178

matanster opened this issue Sep 28, 2020 · 1 comment
Labels

Comments

@matanster
Copy link

@matanster matanster commented Sep 28, 2020

I'm probably doing something wrong, but unlike older versions of the API of this library still implied out there, in the latest version, the fake_input method requires a self argument, implying a slightly contrived usage like the one I implemented below:

from Xlib import X
from Xlib.display import Display
from Xlib.ext import xtest  

class GlobalMouseClickSender(object):

    def __init__(self):
        self.disp = Display()
        self.display = self.disp.display # oddly necessary inside the API method fake_input

    def send_mouse_click(self):
        pointer_data = self.disp.screen().root.query_pointer()
        pprint(pointer_data)

        xtest.fake_input(
            self,
            event_type = X.ButtonPress,
            detail = X.Button1,
            x = pointer_data.root_x, y = pointer_data.root_y)

        xtest.fake_input(
            self,
            event_type = X.ButtonRelease,
            detail = X.Button1,
            x = pointer_data.root_x, y = pointer_data.root_y)

        self.disp.flush()


g = GlobalMouseClickSender()
g.send_mouse_click()

Or at least, that's how I wired a self object for the function call, one having self.display be what fake_input expects it to be.

This works, but I wonder whether there is a simpler way intended.

@petli
Copy link
Contributor

@petli petli commented Sep 28, 2020

The idea with extensions is that they should add methods to the X objects they extend, so it ought to be possible to do this:

self.disp.fake_input(
            event_type = X.ButtonPress,
            detail = X.Button1,
            x = pointer_data.root_x, y = pointer_data.root_y)
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
3 participants
You can’t perform that action at this time.
X Tutup