photo
Jordan Sissel
geek

Mon, 18 Jun 2007

xdo - do (keyboard or mouse) things in X

Yesterday, I talked about macros. I spent some time coding today and I now have a tool that will let you execute raw keyboard and mouse input into X using the XTEST extension.

The primary example I used was focusing firefox's URL bar without the mouse. The sequence was this: Switch to Desktop 2 (I press Alt+2), focus firefox's URL bar (using control+l) and clear it.

The result is a simple tool I'm tentatively calling 'xdo'. You can download the source here. Compile instructions are at the top of the file.

The top of xdo.c details the implemented commands, so let's cut to an example:

% echo 'key alt+2; sleep 1; key ctrl+l; key BackSpace' | ./xdo
It does exactly what you think. The 'sleep' command has values in milliseconds, and is only necessary to slow down so that events can propgate fast enough (window focus changes, etc).

Another reasonable example would be to say "firefox, open a new tab and load the URL in my clipboard":

# My clipboard contains a valid url, say, "http://www.google.com/"
(echo "key alt+2; sleep 1; key ctrl+l; key BackSpace;"
 echo "move 55 55; sleep 1; click 2; key Return") | ./xdo
Seems complex, but look at what's really happening: Go to desktop 2, focus urlbar, hit backspace (clearing it), move the mouse cursor to 55,55 (a point inside the urlbar for me), hit middle mouse button to paste.

Change "ctrl+l" to ctrl+k (unix firefox) to focus the "Search" box instead, and change the 'move' command to cursor over the search box to paste instead, and suddenly you can bind a simple keystroke to search for whatever is in your X clipboard. Useful.

One of the neater features is that you can 'type' text:

% echo 'type echo hello there; key Return' | ./xdo
echo hello there
% echo hello there
hello there

Comments: 5 (view comments)
Tags: , , , , , ,
Permalink: /geekery/xdo
posted at: 02:18


5 responses to 'xdo - do (keyboard or mouse) things in X'

Assume Rhino posted at Tue Jun 19 05:59:03 2007...
Sounds like a great tool! One question, can it simulate mouse clicks? Say I want to show the right click menu (context menu) in Finder or another application by pressing e.g. Ctrl+x. Is this possible?

Jordan Sissel posted at Tue Jun 19 07:15:25 2007...
Yes. With 'click 3' you will send a right click. ('2' would be middle mouse).

I'm working on a lightweight interface to calling functions provided by xdo and other tools. Think OS X's quicksilver tool but for X.

Spoonman posted at Tue Jun 19 13:35:23 2007...
Freakin' A!  I've been looking for something like this for ages.  Between this and wmctrl, I'm all set finally!  It just amazes me that in all of the years Linux has been around that this is the first time someone's built something like this...

Spoonman posted at Tue Jun 19 13:36:13 2007...
Freakin' A!  I've been looking for something like this for ages.  Between this and wmctrl, I'm all set finally!  It just amazes me that in all of the years Linux has been around that this is the first time someone's built something like this...

Sefa Denizoğlu posted at Sun Dec 16 13:57:53 2007...
It seems that this is what I look for. I need a pseudo key entry or mouse click so that my screen and ACPID doesn't interrupt when I just want to leave my laptop for a long download or smth else.. perhaps I can make a regular task out of it via cron?


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. Not posted or recorded anywhere, ever)
URL (also optional)
Comment:


Search this site

Navigation

Metadata

Home About Resume My Code

Articles

ARP Security Dynamic DNS with DHCP OpenLDAP+Kerberos+SASL PPP over SSH SSH Security: /bin/false Week of Unix Tools Work Efficiency

Projects

fex firefox tabsearch firefox urledit grok keynav liboverride newpsm (FreeBSD) nis2ldap pam_captcha poor man's backup Solaris audio utility xboxproxy xdotool xmlpresenter xpathtool misc scripts

Presentations

Yahoo! Hack Day '06 Unix Essentials Vi/Vim Essentials

Tag Cloud

Calendar

< June 2007 >
SuMoTuWeThFrSa
      1 2
3 4 5 6 7 8 9
10111213141516
17181920212223
24252627282930

Friends

BarCamp Kent Brewster Tantek Çelik John Resig Wesley Shields Tyler Shields

Technorati