Search this site


Metadata

Articles

Projects

Presentations

xdotool - fake keyboard/mouse input

What is xdotool?

This tool 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.

Mailing list

The xdotool users mailing list is: xdotool-users@googlegroups.com

I'll be announcing new versions on this mailing list. Additionally, if you want help or want to contribute patches to xdotool, the mailing list is a good place to go.

If you want to file a bug, you can do that on my googlecode issue tracker.

Prerequisites

  • xlib (pkg-config xlib) - Standard Xlib library
  • xtst (pkg-config xtest) - XTEST library

Download

xdotool-20090612.tar.gz

Looking for older versions? Check the archive.

Build Instructions

'make xdotool'

If the build fails, it might be because you don't have the required libraries and header files installed. You will need to set install them, and if you don't have pkg-config for x11 and xtst, set DEFAULT_LIBS and DEFAULT_INC (see the Makefile) correctly.

How to use it

Basic usage is: xdotool <cmd> <args>

Read the documentation here

Example: focus the firefox url bar

WID=`xdotool search "Mozilla Firefox" | head -1`
xdotool windowfocus $WID
xdotool key ctrl+l

Example: Resize all visible gnome-terminal windows

WIDS=`xdotool search --onlyvisible --name "gnome-terminal"`
for id in $WIDS; do
  xdotool windowsize $id 500 500
done

92 responses to 'xdotool - fake keyboard/mouse input'

Showing last 15 comments... (Click here to view all comments)

Mike wrote at Wed Mar 4 02:19:51 2009...
On further investigation of the windowmove not working I can confirm that the gnome terminal will move and stay moved.  Try this with Firefox and it jumps back to where it was originally.

Can anyone else confirm this, is there a workaround, am I picking the wrong window?

Firefox will move to 0 0 and the screen updates with the Window in the correct place.  The problem is when you click anywhere in the newly moved window that it jumps back to the original position.

Thanks

Mike

Jordan Sissel wrote at Fri Mar 6 01:45:13 2009...
@Mike,

I'll try and reproduce it and get back to you. It's totally possible more modern window managers and toolkits expect different messages when the window is moved.

cron wrote at Wed Mar 25 13:04:54 2009...
Oh, wow, I can finally bind a key to simulate clicking the middle mouse button! Thank you, you've made a simple nerd very happy :-)

Steven wrote at Sat Apr 4 22:45:12 2009...
I've run into some interestingly quirky behavior with xdotool when it comes to multiple mouse buttons being used.  I am trying to be able to use a a few mouse buttons as keyboard keys like I can in windows on my Logitech MX100.  Specifically, I use shift, alt, control, tab, and keypad *.

My xbindkeys OR openbox config - tried both just to make sure it wasn't xbindkeys - have press b10 as "xdotool keydown shift".  My shift + release b10 as "xdotool keyup shift".

Test 1:
-open terminal
-type numbers
-hold down b10
--continue pressing numbers
-release b10
output: "1223123!@#@!#!@#12312313"

Test 2:
-open terminal
-type numbers
-hold down b10
--left click mouse
-release b10
-press more numbers
output: "21312!#!@#!!@#!@#!@#!@#!@#"

Shift gets stuck, until I either press the actual shift key, or I press/release b10 again.  Looking at xev output, I discovered that when pressing/releasing b10 xev displayed the shift key and not button 10.  However, if I left clicked while holding b10 - it did display the release of b10, and not the release of the shift key.  That certainly explains why shift is stuck, but not why it is never released.

My best guess is that there is a limitation or bug involved with holding down a mouse button and clicking a different mouse button. 

I have tried a number different configs to try and work around the issue, but I haven't come up with something that works yet.

Below are the configs I used for xbindkeys OR openbox to get the results.

.xbindkeysrc for mouse button 10 =  shift (untested, but should work)
# Mouse 10 to shift
"xdotool keydown shift"
b:10
"xdotool keyup shift"
release + shift + b:10

openbox config for button 10 = shift
  <mousebind button="Button10" action="Press">
  <action name="Execute">
  <command>xdotool keydown shift</command>
  </action>
  </mousebind>
  <mousebind button="S-Button10" action="Release">
  <action name="Execute">
  <command>xdotool keyup shift</command>
  </action>
  </mousebind>

brettdemerais wrote at Mon Apr 13 01:56:44 2009...
alternate email brettdemerais@hotmail.com

Dear Jordan Sissel, I was hoping you might beable to help me with one of my hobbies. background information. I like typing so I made my own typing program sorta. I like it. So all it is, is just a slide show and I type the slides. the slides change every one second. I would like to have it do something else. The slide show can be changed manually with mouse clicks.
So I basically am searching for some thing like:
keyboard input on one computer results in slide changing on another computer;;
so I am looking for keyboard input on first computer results in the output of a "mouse Click" on the first computer which is then fed to the second computer.
================================================
I have down loaded a "mouse click".

I have a program which lets me do some thing neat. on pressing any key, I can open a file, and it allows me to give each key a unique file. I was going to try to put the mouse click on each letter but just as I started I realized the out put would go to the speaker output.
=================================================
I would be happy if I could find something. What I think would do it would be if I could make a file which has a computer program? or computer subroutine?==
I could then touch a key and my program could open this program or sub routine.
================================================
I am kind of dreaming and hoping this program or subroutine would ask the first computer to send a "mouse click" to one of my output connectors, and at the same time use computer language to ask the target computer to use the mouse click as a mouse click. I would really appreciate it if you could lead me in some sort of direction. there is more than one way to skin a cat and the cat hates all of them. I am also searching the net to see if I can find a slide show program which allows one to change slides by touching any key on the keyboard. I would really appreciate any assistance. please and thank you yours sincerely brett

brettdemerais wrote at Mon Apr 13 01:57:08 2009...
alternate email brettdemerais@hotmail.com

Dear Jordan Sissel, I was hoping you might beable to help me with one of my hobbies. background information. I like typing so I made my own typing program sorta. I like it. So all it is, is just a slide show and I type the slides. the slides change every one second. I would like to have it do something else. The slide show can be changed manually with mouse clicks.
So I basically am searching for some thing like:
keyboard input on one computer results in slide changing on another computer;;
so I am looking for keyboard input on first computer results in the output of a "mouse Click" on the first computer which is then fed to the second computer.
================================================
I have down loaded a "mouse click".

I have a program which lets me do some thing neat. on pressing any key, I can open a file, and it allows me to give each key a unique file. I was going to try to put the mouse click on each letter but just as I started I realized the out put would go to the speaker output.
=================================================
I would be happy if I could find something. What I think would do it would be if I could make a file which has a computer program? or computer subroutine?==
I could then touch a key and my program could open this program or sub routine.
================================================
I am kind of dreaming and hoping this program or subroutine would ask the first computer to send a "mouse click" to one of my output connectors, and at the same time use computer language to ask the target computer to use the mouse click as a mouse click. I would really appreciate it if you could lead me in some sort of direction. there is more than one way to skin a cat and the cat hates all of them. I am also searching the net to see if I can find a slide show program which allows one to change slides by touching any key on the keyboard. I would really appreciate any assistance. please and thank you yours sincerely brett

Brett Dea wrote at Sun Apr 19 23:15:31 2009...
Dear Jordan Sissel,

Brett Demerais wrote at Sun Apr 19 23:19:34 2009...
Dear Jordan Sissel,
  Is it possible to have one computer send a mouse click to a USB port every time any key on the keyboard is pressed? If it is easy could you tell me how?
  I bought a program which lets me select any key and then have that key open a file.
  I would appreciate any help here. please and thank you Brett Demerais

linked wrote at Tue Apr 21 15:27:16 2009...
Hi, is there a way to send a key to a windows wihtout focus ?
example:

xdotool $WID key F3

Something like this would be great.

Mike wrote at Tue May 5 14:05:30 2009...
cool app.

I'm interested in sending keyboard/mouse to a VM, but I'm thinking that after you've sent a click or keyboard sequence to the VM to active the window you've turned control over to another window manager.  Trying to send stuff to vmware server console and it just stops after I grab VM input.  Anyone using it for something similar or have suggestions ?

Mike wrote at Tue May 5 14:11:16 2009...
cool app.

I'm interested in sending keyboard/mouse to a VM, but I'm thinking that after you've sent a click or keyboard sequence to the VM to active the window you've turned control over to another window manager.  Trying to send stuff to vmware server console and it just stops after I grab VM input.  Anyone using it for something similar or have suggestions ?

Hanna Frangiyyeh wrote at Sat Jun 6 23:40:04 2009...
Hi;
I'm trying to use xdotool to control an application that I have.  I'm able the active the window and mouve the mouse.  However, when I do click the mouse the button does not respond.  I tried to use "xdotool mousedown 1" instead of using "xdotool click 1".  The samething nothing happened, however I accidently moved the mouse just a bit over the button I was clicking and to my suprise the buton got clicked.
Any idea why and how to get it to work.
Thanks

Frenchn00b wrote at Sat Jun 13 00:58:17 2009...
Hello,

I used:
xdotool key Up
into the .lircrc.

When it uses mplayer, no problem: it works.
But in the menu of FREEVO, the UP from the remote resutls in 2 times x UP, and it means that 1 is too much :(

Best regards
xdotool rocks

picca wrote at Tue Jun 16 01:24:49 2009...
Hi there. I just stumbled across your great application. It just works on some sort of applications (gvim, yakuake, ...), but does not work in wine for me. For example:

notepad & sleep 3;  WID=`xdotool search "notepad" | head -1`; echo $WID; xdotool type "hello" --window $WID

Is this xdotool issue, or wine issue, or is it completely nonsense? I'm using wine 1.1.4 (because of nasty bug in Warcraft 3).

Mark Harrison wrote at Mon Jun 22 21:04:15 2009...
Hmm, is ther a reason I'm getting twice the number of windows found when I search?  Here is a quick demo, I create two gnome-terminals, xlsclients finds two, but xdotool seems to find four.  -- thanks!!

$ gnome-terminal --disable-factory --class=xyzzy &
$ gnome-terminal --disable-factory --class=xyzzy &
$ xdotool search --class xyzzy|wc -l
  4
$ xlsclients -l|grep xyzzy |wc -l
  2
$ ps auxww|grep '[x]yzzy'|wc -l
  2


Leave a reply

You need javascript enabled to use this form. Anti-spam efforts ongoing. Also, if the comment doesn't show up, it's because the form expired. Go back and copy your comment, reload the form, and resubmit. Apologies if this is a hassle, I'm just playing with antispam methods right now. If this insists on not working, please email me about it.

Name (required)
E-mail (optional, if you want me to be able to email you back)
URL (also optional)
Comment: