Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I control the keyboard and mouse with Python?

How can I control the mouse and keyboard in Python?

The idea is to do the same as the Robot() class in Java. Be able to say: move the mouse from here to here, click there, write that whatever is on the screen.

For Windows there is win32api but I'm using mainly Linux.

For Linux there is Xlib but does it works for keyboard as well? (found only reference to the mouse)

Is there a cross-platform solution? (Linux, Windows and even OS X would be the great.)

like image 401
Martin Trigaux Avatar asked Dec 22 '09 12:12

Martin Trigaux


People also ask

Can you control your mouse with Python?

In order to control a mouse using Python, you may use the PyAutoGUI library. Next, you'll see the following 4 scenarios which demonstrate how to control a mouse using Python by: Moving a mouse cursor to a specific location. Clicking on a specific location.

How do I make my mouse move automatically in Python?

This code uses moveTo() function, which takes x and y coordinates, and an optional duration argument. This function moves your mouse pointer from it's current location to x, y coordinate, and takes time as specified by duration argument to do so.

How do you make a keyboard clicker in Python?

Use the pyautogui Module to Create an Auto Clicker in Python The pyautogui module can create scripts that control the mouse and keyboard of the device. We can use the pyautogui. click() function to click the mouse. We can move the mouse beforehand to the required position using the pyautogui.


1 Answers

A cross platform solution on linux, windows and mac is autopy. https://github.com/msanders/autopy/

It allows controlling mouse and keyboard, taking screenshots, and finding small bitmaps on larger bitmaps and should be very convenient if you want to automate some gui application you have no control on.

like image 178
Eloims Avatar answered Nov 15 '22 21:11

Eloims