How can I control the keyboard and mouse with Python?
I use dogtail (https://fedorahosted.org/dogtail/) to do such things, using this I have created an automated testing framework for my Linux(Ubuntu) app. That framework clicks buttons and types into text fields.
see the gedit example, https://fedorahosted.org/dogtail/browser/examples/gedit-test-utf8-procedural-api.py
So just use dogtail e.g
dogtail.rawinput.click(100, 100)
I can advise you PyAutoGUI, it allows to full control Mouse and Keyboard and get Screenshots and even you can locate images within the screen (like: where is the button?), very useful to automate clicks dynamically. It works for Windows, macOS, and Linux.
For example:
>>> import pyautogui
>>> screenWidth, screenHeight = pyautogui.size()
>>> pyautogui.moveTo(screenWidth / 2, screenHeight / 2)
Check out the Introduction page.