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)?
1 Answer
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.
-
2Do you know how to run this command inside a desktop (e.g. Mate or Gnome)? For example, if I set this command to a keyboard shortcut in Mate it doesn't do anything. It only works if I execute it at command line.– trusktrFeb 20, 2014 at 8:01
-
5You need to set the
$DISPAY
variable. Something like this:DISPLAY=:0 xdotool click 1
– chaosFeb 20, 2014 at 15:24