Is there a terminal command that will click the mouse?

I am looking for a way to click the mouse, as it is in its current location or in a specific location on the screen, after x minutes. Is there any way to do this with a terminal command (preferably with the programs Ubuntu has installed by default)?


Solution 1:

Yes there is xdotool. xdotool is a automation tool from X11. To install it type

sudo apt-get install xdotool

To click the mouse via terminal command type:

xdotool click <button>

where button is 1 for left mouse button, 2 for middle, 3 for right, 4 for wheel up and 5 for wheel down.

So a click with the left mouse button is:

xdotool click 1

To move the mouse to a specific position on the screen type

xdotool mousemove 120 100

So the mouse is moved 120 pixels right and 100 pixels down from the top left corner of the screen.

If you want to use this in a cron job (to repeat this every x minutes), don't forget to populate the $DISPLAY environment variable in your crontab.