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> ===


First enable the actkbd service (see below).<br />
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 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 />
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 you discover the right one, it will report key presses like so:<br />
 
<code>Event: <number>:key</code><br />
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.
<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.
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.