Skip to content

Instantly share code, notes, and snippets.

@rampfox
Created December 24, 2021 13:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rampfox/f07b1400669731e168dd36a417e2886c to your computer and use it in GitHub Desktop.
Save rampfox/f07b1400669731e168dd36a417e2886c to your computer and use it in GitHub Desktop.
xdotool - A macro mouse and keyboard for raspberry pi

xdotool - command-line X11 automation tool


A macro mouse and keyboard for raspberry pi

xdotool lets you programatically (or manually) simulate keyboard input and mouse activity, move and resize windows, etc. It does this using X11's XTEST extension and other Xlib functions.

how to install

in terminal:

sudo apt-get install xdotool


Mouse Commands

click [options] button

Send a click, that is, a mousedown followed by mouseup for the given button with a short delay between the two (currently 12ms).

Buttons generally map this way:

Left mouse is 1, middle is 2, right is 3, wheel up is 4, wheel down is 5.

REPEAT

Specify how many times to click. Default is 1.

For a double-click, use --repeat 2


mousemove [options] x y OR 'restore'

Move the mouse to the specific X and Y coordinates on the screen.

You can move the mouse to the previous location if you specify 'restore' instead of an X and Y coordinate. Restoring only works if you have moved previously in this same command invocation. Further, it does not work with the --window option.

For example, to click the top-left corner of the screen and move the mouse to the original position before you moved it, use this: xdotool mousemove 0 0 click 1 mousemove restore

get mouse location

to get specific X and Y location of the mouse xdotool getmouselocation --shell

example:

% xdotool getmouselocation --shell

X=880
Y=443
SCREEN=0
WINDOW=16777250

sleep

Sleep for a specified period. Fractions of seconds (like 1.3, or 0.4) are valid sleep 1


my personal template
create .sh file

touch template.sh nano template.sh

write this inside template.sh

#!/usr/local/bin/xdotool
xdotool sleep 30 mousemove 906 77 click 1 sleep 5 mousemove 509 523 click 1

source:

manpages.ubuntu.com/

linuxcommandlibrary.com/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment