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.
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: 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/
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.
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.
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.
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.
In the console, you can bind keys with loadkeys
, like this:
# loadkeys <<EOF keycode 59 = F1 string F1 = "testing" EOFGet 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).