Utility to count keys presses on a Linux system. Useful for determining the frequency with which particular keys and key combinations are used when developing a keyboard layout.
This project is hosted on Codeberg and reluctantly mirrored on GitHub. Unfortunately, to be included in the Julia general repository it is (currently) necessary to be hosted on GitHub, but I encourage all who can to give up GitHub.
Once you have a working Julia installation use the following command
sudo julia -e 'using Pkg; Pkg.add("KeyCounter"); using KeyCounter; install()'
Alternatively, start Julia as root using sudo julia
. In the REPL press ]
to enter the package prompt and then use add KeyCounter
to download the package. Once this is complete, press backspace to exit the package prompt and install the program using
using KeyCounter
install()
KeyCounter needs to read keyboard events from a file in /dev/input
. However, there are several files numbered event0
, event1
, etc and which corresponds to your keyboard is somewhat random. KeyCounter will attempt to autodetect the correct one, but this is likely to not succeed by itself.
Depending on how strange your setup or keyboard is, you should be able to auto detect your keyboard by supplying the keyboard
parameter with the make and model of your keyboard (ie "Razer Blackwidow").
If KeyCounter can't determine the keyboard number correctly then you may be able to determine the correct event number by examining the text file /proc/bus/input/devices
. Within this file look for a section with the correct N: [Name]
line and a corresponding H: ... kbd eventN
line.
Alternatively, use sudo hexdump /dev/input/eventN
for each N in turn and type some keys and see if there is any data produced. For the correct N you should receive data whenever a key is pressed or released.
The correct value of N can then be passed to KeyCounter with the event
parameter.
First sudo julia
and then
using KeyCounter
countkeys()
KeyCounter will attempt to auto detect the correct keyboard device. If this doesn't work you can supply the make and model of the keyboard or the correct event number, along with other settings, as keyword arguments to countkeys
. Accepted keywords are:
* keyboard: (String) name of the keyboard to assist with autodetecting. Using just keywords like the make and model works best (ie "logitech g512")
* event: (Int) number of the event file to read from
* input: (String) event file to read from (ie /dev/input/event0). Overrides `event` setting
* output: (String) filename to save results to
* interval: (String) frequency to save results, in the format `[Nd][Nh][Nm][Ns]`
* quiet: (Bool) whether to suppress output
* debug: (Bool) whether to display debugging information (overrides `quiet`)
* user: (Int) user id for ownership of the output file (as we are running as root)
To stop counting keys, simply type <CTRL>+C
(^C
) or, if running in the background, send SIGINT to the process. Keys counted will be saved to the output file before exiting.
From the command line use
keycounter
This will use default settings and attempt to auto detect your keyboard. For list of available options use
keycounter --help
To stop counting keys, simply type <CTRL>+C
(^C
) or, if running in the background, send SIGINT to the process. Keys counted will be saved to the output file before exiting.
From the command line use
keycounter --uninstall
Alternatively, sudo julia
and then
using KeyCounter
uninstall()
Then enter the package prompt using ]
and use remove KeyCounter
to remove this package.
Copyright 2023 Harry Ray. Licensed under GPLv3.
Keymaps originally from logkeys
, used under GPLv3.