
36
|
Chapter 2, Console
#11 Energize Your Console with Macro Music Magic
HACK
HACK
#11
Energize Your Console
with Macro Music Magic Hack #11
Redefine keys to issue commands at the command line.
You can exploit the power of the preceding keyboard customization tech-
nique to a much greater degree than just redefining the action of a key. You
can actually define keys to send strings of characters, which, at the console,
means issuing commands.
In this example, you’re going to redefine keys to control your CD-ROM as a
CD player. Even if you have a plain keyboard, you can simply use unusual
key combinations such as Ctrl-Alt-Right Arrow to perform the kind of magic
you’re about to explore. If you can determine the keycodes generated by any
special keys you have on your Internet or multimedia keyboard, you can use
those keys instead.
Defining the Magic
First, you want to create a file called /etc/mykeys, or add to your existing /etc/
mykeys file if you are combining this hack with “Redefine Keyboard
Actions”
[Hack #10]. You will place in /etc/mykeys string definitions that repre-
sent commands. The
cdtool program is really handy for controlling a CD
player at the command line without a bothersome user interface. You can
use another tool if you prefer, but you’ll have to substitute your tool’s com-
mands for the ones defined by
cdtool.
Assume you are using
cdtool to define commands to play a CD, stop play-
ing it,