I don't think you can get a "real signal from the keyboard" directly
in a normal user-space
program. Whether you are programming in C/C++ or in Assembler language doesn't make a difference in this regard. I think you would have to write a kernel-module
and load it into the Linux kernel in order to get this kind of "low-level" hardware access. But that would require a deep understanding of kernel hacking and the hardware.
(and, of course, it would be very hardware-specific and non-portable)
Fortunately, the Linux kernel already provides an user-space interface to the keyboard, as a device file:
#define KEYMAP_SIZE ((KEY_MAX / 8) + 1)
FILE *kbd = fopen("/dev/input/by-path/platform-i8042-serio-0-event-kbd", "r");
fputs("Error Failed to open keyboard device!\n", stderr);
memset(key_map, 0, sizeof(key_map));
ioctl(fileno(kbd), EVIOCGKEY(sizeof(key_map)), key_map);
for (size_t i = 0; i < KEYMAP_SIZE; ++i)
Above code dumps the current state of all keys (including Shift, Ctrl and Alt), in regular intervals. If you are interested in a specific key, then you just need to extract the proper bit from the key_map
You may need to run this with
, otherwise permission to the keyboard device may be denied.