Actkbd: Difference between revisions

imported>Samueldr
WIP re-works sections
 
Pigs (talk | contribs)
m add category configuration
 
(6 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{DISPLAYTITLE:actkbd}}
{{DISPLAYTITLE:actkbd}}
<code>actkbd</code> is a keyboard shortcut daemon that works at the system level. It does so through reading the events directly from the input devices, thus working whether a graphical session is running or not.
<code>actkbd</code> is a keyboard shortcut daemon that works at the system level. It does so through reading the events directly from the input devices, thus working whether a graphical session is running or not.


Line 11: Line 10:
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 26:
{{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 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.
 
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>
 
This command will also list all available input devices, two lines per.
 
<pre>
cat /proc/bus/input/devices | grep "Name\|Handlers"
</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>
fKeys: 33
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, from the [[Backlight]] page will configure the brightness control keys to use <code>light</code> to control the brightness.
 
<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.


First enable the actkbd service (see below).<br />
[[Category:Configuration]]
To read key codes via actkbd, you need to select the right input event provider from /dev/input/. Each input device generating input events has it's own entry there, enumerated with an number. To find out which one generates the events from the hotkeys, it is viable (if tedious) to run the below command with each available entry, and see which one generates event notifications when pressing the brightness hotkeys:<br />
<code>actkbd -n -s -d /dev/input/event#</code><br />
Once you discover the right one, it will report key presses like so:<br />
<code>Event: <number>:key</code><br />
<code>Event: <number>:rel</code><br />
Those represent the key-press and key-release actions. The number is the key code to use for mapping.