Saturday, April 15, 2006

Send hotkeys to X.

This is a micro how-to to explain how (there are many ways, I'll explain one) to send acpi hotkeys to the X server. If your keys don't generate acpi events...well, you may be able to use evrouter or some other tricks, but not this.

1) let your hotkey generate an ACPI event, see /var/log/acpid. In there you'll find something like this (different for each laptop/acpi interface)
received event "sony/hotkey SPIC 00000001 00000029"

2) edit /etc/acpid/events/hotkey, where hotkey is a new file that can have any name, and insert something like:
action=/etc/acpid/actions/ %e

where event is taken from /var/log/acpid and action is an executable shell script. %e passes the whole event string.

3) edit your shell script with a case switch, and switch on the changing part (e.g. for me 00000029 is the part that changes for different hotkeys, so switch $4, i.e. parameter n. 4).

4) when is the case of your hotkey add something like
acpi_fakekey 226
(you need to compile have acpi_fakekey, is in here). This will translate a 226 keycode to the X server. Restart acpid.

5) Now, map the keycode to a key, via xmodmap. Refer to man xmodmap. For example
echo "keycode 226 = F13" >> ~/.Xmodmap
And then since X has received a keypress (in this case F13) let your WM to take care of it. (they all have something for hotkeys, refer to your documentation).

No comments: