Skip to content

mtkld/keymeter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

🔑 Keymeter

Keymeter is a real-time keypress tracker for Linux that monitors keyboard usage from a specified input device using libevdev. It keeps track of total key presses, calculates typing speed, and implements a "credit system" to associate effort or attention with input usage over time. It outputs a compact statistics file that can be used by other tools or visualized externally.

Features

  • ✅ Tracks all key release events from a given input device

  • ✅ Logs:

    • Total key presses
    • Typing speed in keys per minute
    • Remaining "credit" balance
  • ✅ Credit system:

    • Each key press reduces credit
    • Background thread recharges credit periodically
    • Beep alerts when low or negative credit is reached
    • The parameters of rate of recharge, initial credit etc can be personalized (but at the moment you likely have to modify the source code as it's hard coded).
  • ✅ Auto-updates a compact output file for live reading

  • ✅ Multithreaded: background stats logger and credit recharger

Motivation

Remind to take breaks. When credits are low, it signals, when exhausted, it will beep for each key press, creating annoyance to encourage break. Credits are recharged continiously regardless of if credit is exhausted or not, encouraging thinking before typing, because time spent thinking gives time to recharge.

Usage

sudo ./keymeter -i /dev/input/by-id/your_keyboard_device -o ~/.var/keymeter/stats.txt -v

Example use:

sudo ./keymeter -i /dev/input/iiglo_keyboard -v -o ~/.tmp/keymeter

How to bind your keyboard device

In the example, i use -i /dev/input/iiglo_keyboard to specify the input device. You need to replace this with your actual keyboard device path.

For help on how to bind your keyboard device, see how I did it in dkd which is another keyboard utility.

Options:

Flag Description
-i Path to the input device (required)
-o Output file for stats (required)
-v Verbose mode (echo stats to stdout)

You can find your keyboard input device with: ls /dev/input/by-id/ or sudo libinput list-devices

Output Format

Keymeter writes a single-line compact report every 10 seconds if keypress count has changed:

1.23 MB - 12800
256
732
  • Line 1: Total key presses (formatted size + raw count)
  • Line 2: Typing speed in keys per minute
  • Line 3: Remaining credit

This format is easy to parse from scripts or live dashboards.

Credit System

The "credit" simulates a consumable input budget:

  • Starts at: 750

  • Each key press: -1

  • Recharges: +6 every 10 seconds

  • Max credit: 2000

  • Beep when:

    • Credit drops to 0 (warning beep)
    • Credit goes below 0 (alert beep)

This can be used for attention tracking, effort budgeting, or alerting based on excessive typing.

Beep Alerts

Requires beep utility installed (e.g., sudo pacman -S beep)

  • Low credit (0): beep -f 100 -l 200
  • Negative credit: beep -f 1000 -l 100

Dependencies

  • libevdev
  • POSIX threads
  • Standard C libraries

Install libevdev on Arch Linux:

sudo pacman -S libevdev

Build

Make file is included, so:

make
sudo make install
make clean

But, a simple gcc build:

gcc -I/usr/include/libevdev-1.0 keymeter.c -levdev -lm -o keymeter ;

I had to specify the exact include path for libevdev on my system, so you may need to adjust the -I flag based on your installation.

Example Output

Total Key Presses: 1.52 MB, 19583/m, 648

🔒 Permissions

Keymeter needs read access to input devices (e.g., /dev/input/event*), so it should be run with sudo or with appropriate group permissions (e.g., input group).

🧪 Potential Use Cases

  • Personal input analytics
  • Productivity monitoring
  • Typing fatigue estimation
  • Gamified focus tracking
  • Triggering break reminders based on usage

About

Measure and rate limit keyboard usage and automatic recharge.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published