3

I want to simulate mouse clicks in Python (and if it is possible, also keyboard inputs) in a Linux system (Ubuntu), so I am able to create a macro for an external program.

I have researched a bit, and found questions like this which use win32api or ctypes to do the job. But since I am working in Ubuntu, those doesn't fit for me.

I also found Xaut (former Xautomation), which is said to simulate mouse and keyboard interactions over Linux systems. But it is hard to install for me, and it lacks documentation and examples anyway.

I really like the win32api solution, it's very simple. Isn't there any similar solution for Linux?

asked Jan 23, 2013 at 8:53

2 Answers 2

5

Unlike Windows, Linux is a secure system by design so injecting/intercepting user events isn't simple :-)

But there are tools which can do the same on Linux (at least when they have xauth credentials, so no snooping/cracking other users on the same computer). Try xdotool which offers a wide range of commands to find and select windows and then send events to them.

xdotool is available for most Linux distributions (debian and rpm based).

Note: For security reasons, synthetic events in X11 have a flag set and some software ignores all events with this flag.

answered Jan 23, 2013 at 9:02
Sign up to request clarification or add additional context in comments.

2 Comments

If I'm going to leave the Python script idea and embracing a tool like this, wouldn't be better to use some macro creator with a GUI? xdotool looks too simple
Use Python to build a wrapper for the script. This way, you can create yourself a macro generator and executor.
2

You can use this:

import pyautogui 
x= #x position
y= #y position
pyautogui.click(x,y)

To install pyautogui visit the official installation page documentation: https://pyautogui.readthedocs.io/en/latest/install.html

To write text automatically use this:

import pyautogui
pyautogui.write('write this example')
answered Dec 13, 2019 at 14:50

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.