Actkbd: Difference between revisions
imported>Samueldr WIP re-works sections |
imported>Samueldr m Finishes up actkbd page |
||
Line 11: | Line 11: | ||
The key codes used by <code>actkbd</code> when binding commands will not match with the key code events <code>xev</code> reports. | The key codes used by <code>actkbd</code> when binding commands will not match with the key code events <code>xev</code> reports. | ||
== Obtaining key codes with <code>xev</code> == | === Obtaining key codes with <code>xev</code> === | ||
While logged into an X session, using <code>nix-shell -p xorg.xev --run "xev -event keyboard"</code> will run <code>xev</code>, with filtering for keyboard events. | While logged into an X session, using <code>nix-shell -p xorg.xev --run "xev -event keyboard"</code> will run <code>xev</code>, with filtering for keyboard events. | ||
Line 27: | Line 27: | ||
{{tip| While the previous statement may be true, it has been observed that for some, if not all, key code events, subtracting 8 to the <code>xev</code> key code will give the expected <code>actkbd</code> event.}} | {{tip| While the previous statement may be true, it has been observed that for some, if not all, key code events, subtracting 8 to the <code>xev</code> key code will give the expected <code>actkbd</code> event.}} | ||
== Obtaining key codes with <code>actkbd</code> == | === Obtaining key codes with <code>actkbd</code> === | ||
To read key codes with <code>actkbd</code>, you will need to select the right input event provider from <tt>/dev/input/</tt>. Each input device generating input events has its own entry there, enumerated with a number. | |||
To read key codes | |||
< | To find out which one generates the events from the hotkeys, it is possible, while tedious, to run the following command with each available entry, and see which one generates event notifications when pressing the wanted key. | ||
Once | |||
<code> | Alternatively, the <code>lsinput</code> from the <tt>input-utils</tt> package<sup>[not upstreamed yet]</sup> allows listing all <tt>/dev/input/</tt> files with a useful name. | ||
< | |||
Another method, which does not require additional packages, will list all the input devices recognized by the X server: | |||
<pre> | |||
journalctl --unit display-manager.service -b0 | grep "Adding input device" | sed -e 's;.*config/udev: ;;' | sort | uniq | |||
</pre> | |||
Finally, some device files will also be listed in the <tt>/dev/input/by-path/</tt> and <tt>/dev/input/by-id/</tt> directories with somewhat recognizable names. | |||
Once the input device found, run the following command (replacing <code>#</code> with the ID) to print the keycodes as <code>actkbd</code> sees them. | |||
<pre> | |||
nix-shell -p actkbd --run "sudo actkbd -n -s -d /dev/input/event#" | |||
</pre> | |||
It will report the keys this way: | |||
<pre> | |||
Keys: 14 | |||
Keys: 29+46 | |||
</pre> | |||
Where key codes with a + represents combinations. The numbers, including combinations can be used in the configuration. | |||
== Sample configuration == | |||
The following configuration will | |||
<syntaxhighlight lang="nix"> | |||
programs.light.enable = true; # Needed for the /run/wrappers/bin/light SUID wrapper. | |||
services.actkbd = { | |||
enable = true; | |||
bindings = [ | |||
{ keys = [ 224 ]; events = [ "key" ]; command = "/run/wrappers/bin/light -A 10"; } | |||
{ keys = [ 225 ]; events = [ "key" ]; command = "/run/wrappers/bin/light -U 10"; } | |||
]; | |||
}; | |||
</syntaxhighlight> | |||
Additionally, the {{nixos:option|sound.mediaKeys.enable}} option will use <code>actkbd</code> to control the media volumes. See the configuration it generates for an additional example. |