Receiving key press and key release events in Linux terminal applications

keypress, linux, ncurses, terminal, tty

Solution

The following links may be of some assistance in using the keyboard raw mode which will give you access to the keyboard events rather than just key releases.

- This Linux Journal article

- This article on SourceForge

- And this HOWTO for when it all goes bad

Raw mode does have the disadvantage that you have to do your own conversion from scan codes to characters though.

Problem

I would like to write a simple C program that will perform different actions based on both "key down" and "key up" events. This program will be run from inside rxvt. What library or mechanism should I use to access both key presses and releases? Is it true that reading `/dev/tty` will only provide key releases? Is this also true for termcap, terminfo, ncurses, and S-Lang? Is there a way to achieve this from within a terminal application?

Original source