I came to know about xdotool while searching for an idea to move mouse and to simulate clicking events for our project.xdotool is a command line automation tool that helps us to 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.Additionally, you can search for windows and move, resize, hide, and modify window properties like the title.To use this utility first we have to install xdotool.I would like to tell you about the commands that xdotool has.If you are interested you may try it by typing the command on terminal.
KEYBOARD COMMANDS:
- key keystroke — Type a given keystroke. Examples being “alt+r”, “Control_L+J”,”ctrl+alt+n”, “BackSpace” and it will function as the key specified.
eg:
I am here going to Simulate paste operation in terminal.let my selected text be “I am Jinu”
open terminal and type xdotool key ctrl+shift+v and it will perform paste operation.
- keydown keystroke –this command is same as above but only the keydown events are sent
eg: xdotool keydown 1 prints 1 continuously as shown in figure.That is it will act as we pressed key 1 down

- keyup keystroke — same as above but only the key up events are sent
- type something to type — enable us to type a series of letters
eg: xdotool type “hai i am jinu” prints hai i am jinu
- mousemove x y — Move the mouse to a specific location (x,y) co=ordinates on the screen
- mousedown button–this command sends “mouse down” for the given button 1==left,2==middle,3==right
- mouseup button –this command sends “mouse up” for the given button
- click button –Send mousedown followed by mouseup for the given button
- getmouselocation — this command gives output the x, y, and screen location of the mouse cursor.
eg: xdotool mousemove 0 0 moves mouse cursor to the left upper corner
eg: xdotool mousedown 1 sends “mouse down” for left button that means left click
eg: xdotool mouseup 1
WINDOW COMMANDS
- search [options] somestring –Search for windows with titles, names, or classes matching somestring.The output is line-delimited list of X window identifiers
- getwindowfocus [-f] — Prints the window id of the currently focused window.
- windowsize [options] windowid width height — Set the window size of the given window
- windowmove windowid x y — Move the window to the given position
- windowfocus windowid — Focus the window
- windowmap window_id — Map a window. In X11 terminology, mapping a window means making it visible on the screen.
- windowraise window_id — Raise the window to the top of the stack. This may not work on all window managers.
- windowunmap window_id — Unmap a window, making it no longer appear on your screen.
options available
–onlyvisible – Show only visible windows in the results.
–title – Match against the window title
–name – Match against the window name
–class – Match against the window class
The default options are “–title –name –class”
eg:

option available:
–usehints – Use window sizing hints when setting width and height.This is useful on terminals.
eg:

eg: xdotool windowmove 60836481 0 0 –move the window with given id to(0,0)co-ordinates
DESKTOP AND WINDOW COMMANDS:
- windowactivate windowid — Activate the window. This command is different from windowfocus: if the window is on another desktop, we will switch to that desktop.It also uses a different method for bringing the window up. I recommend trying this command before using windowfocus, as it will work on more window managers.
- getactivewindow — Output the current active window. This command is often more reliable than getwindowfocus.
- set_num_desktops number — Changes the number of desktops or workspaces.
- get_num_desktops — Output the current number of desktops.
- set_desktop desktop_number — Change the current view to the specified desktop.
- get_desktop — Output the current desktop in view.
- set_desktop_for_window window_id desktop_number — Move a window to a different desktop.
- get_desktop_for_window window_id — Output the desktop currently containing the given window.






September 6th, 2011 at 1:34 am
Thanks