Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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)?

share|improve this question
    
Ubuntu comes with Python, and because Python is the swiss-knife (or is that Perl?). No, Python is the glue. So look here: stackoverflow.com/questions/3545230/… –  user85164 Nov 5 '13 at 2:19

1 Answer 1

up vote 7 down vote accepted

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.

share|improve this answer
    
Do 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. –  trusktr Feb 20 at 8:01
1  
You need to set the $DISPAY variable. Something like this: DISPLAY=:0 xdotool click 1 –  chaos Feb 20 at 15:24

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.