Skip to content

leo-arch/keypress

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Keypress ⌨

A raw keyboard input reader


Keypress

1. Description

1.a. Interactive mode

By default, keypress runs in interactive mode. In this mode, it generates a byte-by-byte representation of keyboard inputs as the user types, whether for individual keys or key combinations. This representation includes the following formats: hexadecimal, octal, decimal, binary, and the corresponding symbols.

Why? Have you ever developed a terminal program dealing with keyboard input? That is why.

Also, keypress is platform agonostic: it works on the TTY, X11, Wayland, and virtually any terminal emulator.

Awful, useful.

Tip

Copy any text you like (yes, including UTF-8 characters) to the primary clipboard, and then paste it into the keypress interface to get the corresponding raw codes.

Did you know, for example, that printf "\xc3\x9f\n" will print an ß (the german Eszett)?
Try with printf "\xf0\x9f\x98\x80\n". Nice!

1.b. Translation mode

By using the -t option, keypress runs in translation mode: it translates a keyboard escape sequence passed as parameter into the corresponding symbolic/text representation. For example:

keypress -t "\x1b[1;7D"

This command will output Ctrl+Alt+Left.

Note

For developers: The translation module can be used as an independent library. Simply include the translate_key.h header in your project (together with the corresponding source file) and use the translate_key function. Here's a quick example:

...
#include "translate_key.h"
...
char str[] = "\x1b[1;7D";
char *keysym = translate_key(str, 0);

if (keysym) {
    printf("%s\n", keysym);
    free(keysym);
}
...

1.c. The Kitty keyboard protocol

Use the -k option to enable support for the Kitty keyboard protocol. Version 0.2.3 or later required.


2. Installation

To install keypress, follow these steps:

git clone https://github.com/leo-arch/keypress
cd keypress
make
sudo make install

3. Uninstallation

To uninstall keypress, use the following command:

sudo make uninstall

4. Similar projects

libtermkey - Easy processing of keyboard entry from terminal-based programs

Note

This library is deprecated. Use libtickit instead.