Created
August 21, 2018 17:48
-
-
Save hluk/2bee5d4281e045c2bfd8a9d475819390 to your computer and use it in GitHub Desktop.
Move Mouse Cursor to Active Window
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import pyatspi | |
def on_object_focused(event): | |
if not event.source.getState().contains(pyatspi.STATE_FOCUSED): | |
return | |
print(event) | |
extents = event.source.get_extents(pyatspi.DESKTOP_COORDS) | |
x = extents.x + extents.width / 2 | |
y = extents.y + extents.height / 2 | |
print('moving mouse to: [{}, {}] ({}-{} @ [{}, {}] {}x{})'.format( | |
x, y, event.host_application.name, event.source_name, | |
extents.x, extents.y, extents.width, extents.height)) | |
pyatspi.Registry.generateMouseEvent(x, y, pyatspi.MOUSE_ABS) | |
def main(): | |
pyatspi.Registry.registerEventListener(on_object_focused, 'focus') | |
try: | |
pyatspi.Registry.start() | |
finally: | |
pyatspi.Registry.stop() | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment