Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Move Mouse Cursor to Active Window
#!/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
You can’t perform that action at this time.