Show Me The Key

repository·master·Indexed 20 days ago

https://github.com/alynxzhou/showmethekey

A screenkey alternative for Wayland that visualizes typing on screen by reading keyboard events directly via libinput/evdev. It consists of a CLI backend that outputs keyboard and pointer button events as JSON and a GTK-based graphical frontend that displays these events in a transparent floating window.

Tokens
1.8K
Snippets
8
Records
12
Agent score
68%

What's inside showmethekey

  1. How the CLI backend and GTK frontend work together

    master

    Show Me The Key is split into two components to handle Wayland security requirements:

    1. CLI Backend: A custom re-write of libinput-debug-events.c based on libinput, libudev, and libevdev. It runs with superuser permissions to read keyboard events directly from /dev/input/ (evdev interface). It outputs key events as JSON lines.
    2. GTK Frontend: A GUI based on GTK that runs the CLI backend as root via pkexec. It displays the key events in a transparent floating window.

    Note on Permissions: Because the program reads directly from the evdev interface to support Wayland, it requires root/superuser permissions. Users in the wheel group may skip password authentication via polkit.

  2. Install Show Me The Key

    master

    Install showmethekey using your distribution's package manager. Recommended methods are provided for AOSC OS, Arch Linux, openSUSE, and Fedora.

    ### AOSC OS
    # apt install showmethekey
    
    ### Arch Linux
    # pacman -S showmethekey
    
    ### openSUSE (Tumbleweed)
    # zypper ar https://download.opensuse.org/repositories/home:/AZhou/openSUSE_Tumbleweed/home:AZhou.repo
    # zypper in showmethekey showmethekey-lang
    
    ### Fedora (COPR)
    # sudo dnf copr enable pesader/showmethekey
    # sudo dnf install showmethekey
  3. Build Show Me The Key from source

    master

    To build from source, ensure you have the following dependencies installed: libevdev, udev (or systemd), libinput, glib2, gtk4, libadwaita, json-glib, cairo, pango, libxkbcommon, polkit, meson, ninja, and gcc.

    Follow these steps to clone, configure, and install:

    $ git clone https://github.com/AlynxZhou/showmethekey.git
    $ cd showmethekey
    $ mkdir build && cd build && meson setup --prefix=/usr . .. && meson compile && meson install
    $ showmethekey-gtk
  4. Run the Show Me The Key GTK application

    master

    The GTK-based graphical interface is initialized via the main function, which sets up localization (locale and text domains) and instantiates the SmtkApp using smtk_app_new(). The application lifecycle is managed by the standard GLib g_application_run loop. To run the application, execute the compiled binary from your terminal.

    # Assuming the binary is named 'showmethekey-gtk'
    ./showmethekey-gtk
  5. Use the Show Me The Key CLI

    master

    The CLI is the backend component of Show Me The Key. It is designed to be run by a frontend (typically with elevated privileges like pkexec) rather than directly by users. It monitors input devices via libinput and outputs key/button events as JSON.

    To stop the backend process, send the string stop\n to its stdin.

  6. Reference: CLI Backend JSON output format

    master

    The CLI backend generates key event data in the following JSON format per line:

    {"event_name": "KEYBOARD_KEY", "event_type": 300, "time_stamp": 39869802, "key_name": "KEY_C", "key_code": 46, "state_name": "PRESSED", "state_code": 1}
  7. Configure Wayland compositor rules for Show Me The Key

    master

    Because Wayland does not allow clients to set their own position or layer, you must use your compositor's window rules to pin the window or make it float. The floating window title is Floating Window - Show Me The Key and the app ID/class is showmethekey-gtk or one.alynx.showmethekey.

    Sway

    Add this to ~/.config/sway/config:

    for_window [app_id="showmethekey-gtk" title="Floating Window - Show Me The Key"] {
      floating enable
      sticky enable
    }

    Hyprland

    Add these to ~/.config/hypr/hyprland.conf:

    windowrulev2 = float,class:^(one.alynx.showmethekey)$
    windowrulev2 = float,class:^(showmethekey-gtk)$
    windowrulev2 = pin,class:^(showmethekey-gtk)$

    GNOME & KDE Plasma

    • GNOME: Right-click the "Clickable Area" on the title bar and select "Always on Top" and "Always on Visible Workspace".
    • KDE Plasma: Right-click "Floating Window - Show Me The Key" on the taskbar, select "Move to Desktop" -> "All Desktops", and "More Actions" -> "Keep Above Others".
  8. Use CLI options for showmethekey-gtk

    master

    You can customize the behavior of the showmethekey-gtk application using command-line flags to control the default visibility of the settings and keys windows:

    • -k: Show the keys window by default (hides the app/settings window).
    • -A: Hide the app/settings window by default.
    • -C: Make the keys window click-through by default (useful if you have configured compositor rules for position and layer).
    $ showmethekey-gtk -k
    $ showmethekey-gtk -A
    $ showmethekey-gtk -C
  9. Output format of Show Me The Key backend

    master

    The backend of Show Me The Key outputs keyboard and pointer button events as single-line JSON objects to stdout. This allows other processes (like a frontend) to parse the stream easily. Each event includes the event name, type, timestamp, key/button name, code, and state.

    Note: The backend uses fflush(stdout) after every event to ensure real-time delivery when used in a pipe.

    {
    "event_name": "KEYBOARD_KEY", 
    "event_type": %d, 
    "time_stamp": %d, 
    "key_name": "%s", 
    "key_code": %d, 
    "state_name": "%s", 
    "state_code": %d
    }
    
    -- OR --
    
    {
    "event_name": "POINTER_BUTTON", 
    "event_type": %d, 
    "time_stamp": %d, 
    "key_name": "%s", 
    "key_code": %d, 
    "state_name": "%s", 
    "state_code": %d
    }
  10. Error codes returned by the backend

    master

    The backend returns specific exit codes based on the failure mode:

    • 0 (NO_ERROR): Success.
    • UDEV_FAILED: Failed to initialize udev.
    • LIBINPUT_FAILED: Failed to initialize libinput from udev.
    • SEAT_FAILED: Failed to set the seat (defaults to seat0).
    • PERMISSION_FAILED: Failed to handle events, likely due to insufficient permissions to access input devices.
  11. CLI options for Show Me The Key backend

    master

    The backend CLI supports the following flags:

    • -h, --help: Display help information and version, then exit.
    • -v, --version: Display the current project version, then exit.
    Usage: showmethekey [OPTION…]
    
    Options:
    	-h, --help	Display help then exit.
    	-v, --version	Display version then exit.