Within the /dev/input
folder of your Linux you will get information about the input events 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.
Inside this documentation you can see how to use it in the 2. Simple Usage
part. I believe that, in your case, a simple fopen
of the file relative to your input will already be necessary. input
information is in /usr/include/linux/input.h
.
To get the information use read
to blocker or ioctl
to non-blocker. This tutorial might 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);