Inside the folder /dev/input
of your Linux you will have information about the events of input of your system. They come in the following format:
struct input_event {
struct timeval time;
unsigned short type;
unsigned short code;
unsigned int value;
};
'time' is the timestamp, it Returns the time at which the Event
happened. Type is for example EV_REL for relative Moment, EV_KEY for a
keypress or release. More types are defined in
include/Uapi/linux/input-Event-codes. h.
'code' is Event code, for example REL_X or KEY_BACKSPACE, Again a
complete list is in include/Uapi/linux/input-Event-codes. h.
'value' is the value the Event Carries. Either a relative change for
EV_REL, Absolute new value for EV_ABS (joysticks ...), or 0 for EV_KEY
for release, 1 for keypress and 2 for autorepeat.
Within this documentation you can see how to use in the 2. Simple Usage
. I believe, in your case, a simple fopen
of your input file will already be needed. Information for input
are in /usr/include/linux/input.h
.
To get the information use read
for blocker or ioctl
for non-blocking. This tutorial may help you.
Look at this example:
FILE fd = fopen("/dev/input/eventX", "r"); //troque o path para o seu caso
char keys[16];
ioctl(fd, EVIOCGKEY(sizeof keys), &keys);
int keyb = keys[KEY_ESC/8]; // ESC, por exemplo
int mask = 1 << (key % 8);
bool state = !(keyb & mask);