xdo - do (keyboard or mouse) things in X
Posted Mon, 18 Jun 2007
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' | ./xdoIt 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") | ./xdoSeems 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
USB Mouse support in newmoused, working.
Posted Thu, 17 Aug 2006
You'll need the new moused framework for this module.
- Download my moused framework (newpsm project on this site)
- Recompile your kernel without "device ums"
- Build moused, build the usbmouse module.
- Run moused: ./moused -m usbmouse -d /dev/uhid0
- Rewrite ugly bits
- Port ums(4) hacks for broken mice
- Test with more mice
- Write uhid joypad support
USB Mouse support in-progress for newmoused/newpsm
Posted Sun, 13 Aug 2006
To see what I mean, look at: src/usr.sbin/usbhidct/usbhid.c.
Look near line 230 (the only read() call in the file). Notice the read() call, but 'dbuf' is NEVER used meaningfully. More specifically, the read is mostly ignored and a loop is done over the 'hids' list. Looks like read()s on usbhid devices pushes data to special places in memory which can be found by using hid_start_parse(). A read() shouldn't be doing this. This is the job for an ioctl() or something. read(), to me, says "give me data so I can use it" - not "update some magic places in memory, thanks"
pam_captcha 1.2 updated
Posted Sat, 25 Mar 2006
Check out the project page for information on pam_captcha and downloading it.