Crikey! A program to generate typed key events on Linux

My husband used to complain about a piece of functionality he missed from Mac and Windows QuickKeys: the ability to assign a key shortcut to a string. For example, he might want to be able to store his username on F1 and then use it quickly in any application. He might even want to do the same for his password, setting aside the obvious security issues.

Linux, despite its generous configurability in nearly every other respect, seems to lack this ability. So I wrote Crikey! Conveniently Repeated Input Key -- a little program that simulates key events.

Download

The latest Crikey is now on GitHub and that's the best place to get it.

You can also get tarballs of earlier versions: see the change log, below.

To build it, just type make -- there's no configure step. You'll need gcc and make (on Ubuntu, install package build-essential). You'll probably also need some X development headers -- on Debian or Ubuntu that means packages libx11-dev x11proto-xext-dev libxt-dev libxtst-dev. (I'm happy to list the packages needed on other distros or OSes if you send them to me.)

Usage (command-line flags)

Usage: crikey [-itxr] [-sS sleeptime] string...
Send key events, as if args was typed in whatever X window currently has focus.
Flags:
        -s seconds: sleep time before sending
        -S milliseconds: sleep time before sending
             Many window managers need a delay for focus shifting
             or to allow a modifier button to be released.
        -i: Interactive (read input from stdin)
        -t: Use XTest to send events (default)
        -x: Use XSendEvent to send events
        -r: Send events to root window (only with XSendEvent)
        -l: Show long (more detailed) help
        -d: Show debug messages

If there are multiple arguments, single spaces will be inserted between them.

There's now a manual page (thanks to Thomas Bracken). I'll include it in the next version of Crikey, but for now, you can get it here:
crikey.1
and install it in /usr/local/man/man1/

Crikey input options

Sample usage:

crikey -s 1 'My long string\nExtending over two lines.'

Using quotes around the string is normally recommended, to avoid problems with your shell treating any characters specially, especially backslashes.

Special characters and syntaxes

Control characters use ^: ^A sends a Control-A
Numeric ASCII codes (decimal only): \27 sends ESC
Special codes: \t tab, \b backspace, \n newline, \r return, \d delete, \e escape, \\ backslash
Modifier keys: \S shift, \C control, \A alt, \M or \W for the "Windows" key. These must be capitalized, and they only apply to the next single character, so \Aabc will send alt-A followed by b and c with no modifier keys.
Special symbols with \( \): \(Return\) ... these are defined in /usr/include/X11/keysymdef.h, but only those defined on your keyboard will likely work.

Miscellany

New in 0.8: I've added symbols for BackSpace and Delete. But more important, I've added two new ways to specify characters.

You can specify characters by symbol using \( and \), using the symbol definitions from /usr/include/X11/keysymdef.h. For example, \(BackSpace\) would insert a backspace character.

You can also specify control characters using the up-caret ^ character. So you could get that same backspace character with ^H.

0.8.1 just fixes a new compiler warning, no functional changes.
0.8.2 adds -lXext to the link line -- some systems added that automatically, but making it explicit is better.
0.8.3 adds a bunch more new ways to specify characters, fixes some bugs, and switches back to XTest as the default (use -x to use XSendEvent).

I also have a new, experimental, Python version called pykey, which requires the python-xlib library. It might be useful for people who don't have a compiler installed, or as a demo of how to generate key events in python-xlib. Try it out: pykey-0.1.

A Note on Xterm

Crikey will work out of the box for most terminal emulators, but xterm blocks events generated with XSendEvent by default. To use crikey with xterm, you have two options:

Setting up Crikey in your Window Manager

The most common way to use Crikey is to bind specific crikey commands to keys in your window manager (for instance, Shift-F12 might send a particular string).

The procedure for making key bindings is different in every window manager, so I've moved the instructions for all the various window managers to a separate page: Making Crikey! work on various window managers.

Similar tools

In the console, you can bind keys with loadkeys, like this:

# loadkeys <<EOF
keycode 59 = F1
string F1 = "testing"
EOF
Get the keycode using showkey. This may still work after you start X, if you run the loadkeys before starting X. Or it may not. No one seems to know why it works inconsistently.

xdotool can also simulate keyboard input, as well as other X events like mouse clicks. If crikey doesn't work for you, or you want a more general tool, check it out.

A program called xte, part of the xautomation project, can also simulate key events.

Some window managers, like Openbox, can simulate key events (see the Crikey on window managers page).


Crikey Change Log:

0.8.4, Apr 30 2010:
Lots of improvements, which sadly I didn't list for the changelog.
0.8.3, August 19 2009:
New ways of specifying characters; make -t the default; add -x and -l arguments; bugfixes.
0.8.2, June 15 2009:
Add -lXext to the link line, needed on some systems.
0.8.1, May 12 2009:
Fix fgets warning that got introduced from the latest stdio.h.
0.8, Jan 13 2009:
Add ^ and \(\) methods of specifying keys. Add BackSpace and Delete.
pykey 0.1, May 25 2008:
New experimental Python version.
0.7, May 25 2008:
Fix XTest (-t) code to send the needed KeyRelease and Shift Press/Release events.
0.6, May 12 2008:
From Glen Smith: Fix special characters that weren't working: % " <
0.5, Nov 9 2004:
From Efraim Feinstein: Add -i option (read from stdin) and -d (print debug output); add "make uninstall" target.
0.4, Mar 27 2004:
Make X events default instead of XTest. Add -s1 syntax as well as -s 1.
0.3:
Add XSendEvent support; code cleanup.
0.2:
Add -s option.
dookey:
First release, called "dookey".

More Software
Shallowsky Home
mail me