GitXplorerGitXplorer
g

layerz

public
9 stars
1 forks
2 issues

Commits

List of commits on branch main.
Unverified
38fe26736b8deb8dfbc01acde796b598b204d769

upgrade to zig 0.11

committed a year ago
Unverified
047afe5f0fe1093382137e8ae49d3c254c3a09e8

integration with uinput is borken

ggwenzek committed 2 years ago
Unverified
b4f0447175b6cb709d3a47069b26e370b5e4fb01

add FileProvider instead of stdout provider

ggwenzek committed 2 years ago
Unverified
ef7c135c49917454e71cbdb0b501d2f99cc14346

add FileProvider instead of stdout provider

ggwenzek committed 2 years ago
Unverified
3331f3d56bd9e2afe591fbb89ccf0a2dc18de281

0.10 std.fs.dir

ggwenzek committed 2 years ago
Unverified
d14e0621760da3ba10a5e7413e012790f36b5e72

upgrade build.zig to zig 0.10

ggwenzek committed 2 years ago

README

The README file for this repository.

LayerZ a Zig utility to control what your keyboard do

This utility intercepts the key events from a specific input device. LayerZ then allow you to rewrite those events on the fly and change what the rest of the OS receives as input.

I've got used to be able to program my mechanical keyboard for a few years now. And when I've to type on my laptop keyboard I also want to control exactly what happens and I want to make some keys easier to reach.

Get started

/!\ This software is still in early stage, and the user experience need to be improved.

  1. Configure which device you want to intercept. This allow to eg only intercept events from your laptop keyboard and ignore external keyboards. To do that edit the KEEB variable in start.sh

  2. Check the keyboard layout and potentially customize it. The layout is specified in main.zig. The default layout adds a new layer which is activated while holding the space bar. Don't hesitate to customize a bit. See below for the reference of what you can do.

  3. Install Zig with a package manager This code was written with Zig 0.11.0. Alternativelly you can use devbox which is an easy to use package manager backed by Nix.

  4. Identify the name of the builting keyboard. Run ls /dev/input/by-path/ to find the name of the usb devices plugged in your laptop.

  5. Run sudo ./start.sh $KEEB from a terminal. This will build the utility and start intercepting the keyboard events. sudo is required for the interception. If the keyboard is not behaving as you would like close the terminal with the mouse :-)

TODO Figure out how to launch this in a daemon

How to ?

How to debug issues

The first thing to do is to build Layerz in debug mode. This will output the received events and the output. Sometimes the keyboard themselves don't send the correct input. For instance my laptop keyboard doesn't detect when "space", "capslock" and "f" are pressed at the same time.

I see libevdev_uinput_write_event failed: Success

This probably means that you can't write to this device, is it open in another terminal/process ? Run pgrep uinput.

How to input a localized character

The keyboard protocol doesn't support localized characters. Those are generated by XKB. Typically you should chose a keyboard layout that have special characters when holding "RightAlt". Then use LayerZ to yield RightAlt and the character of your choice. If you don't find a keyboard layout that has all the special characters you want, you will need to modify an exisiting one. Note that not all applications receives the special characters from XKB.

TODO: could we generate the XKB layout ourselves ?

Performance

I didn't find a good way to measure the latency, because depending on the layout, Layerz will delay some ambiguous key presses until the next key. So in this case the latency is a feature. Instead I'm measuring throughput, by piping a full list of keys event through the program. Layerz then don't need to wait for keys and we can measure the actual time per key. This include reading and writing, but that's a cost created by using Layerz. We spend about 25% of our time in the kernel mode, making syscalls to read/write events.

Reference

Features:

  • k: Remap a key to another key
  • Remap a key to two keys (typically shift + key)
    • s: Remap a key to a shifted key
    • ctrl: Remap a key to ctrl+key
    • altgr: Remap a key to a key + altgr. Useful for inputing localized chars.
  • lt: Layer toggle
  • lh: Layer hold
  • xx: Disable a key
  • __: Don't modify key behavior

TODO: allow to input several modifiers TODO: mod hold TODO: add combos (map a combination of keys to another) TODO: add chord (map a succession of keys to another) TODO: generate Zig doc for the DSL

Alternatives

I discovered those tools after I started myself, otherwise I would probably just have chose one of them, but hey, maybe it will save you some trouble: