I am not certain if this is ultimately the correct place to ask this but I am developing a program which requires real-time input from the user. That is; it needs to be able to read the keys being pressed(and optionally held down and released) in real time. What makes this issue a bit troublesome is that I absolutely can not use any kinds of libraries for this; not even the standard C library. So this needs to be handled with raw kernel syscalls and
I thought I would set stdin to non-blocking mode with
O_NONBLOCK and then read the input data from stdin. However, to my surprise my code seems not to be working correctly. Right now it seems that the input gets to be read from stdin after the Enter key is being pressed. The tricky part is that I am finding it troublesome to figure out whether it is the fault of:
- My code not behaving right(most probable)
- My terminal/user/process(whatever handles it?) not having non-blocking write access to stdin(not probable).
- Me assuming wrongly that I can read direct keyboard input from stdin.
So my question is that what is the best/usual way of reading direct keyboard interaction if not by setting the stdin to non-blocking mode and reading the keyboard input data from there? Or am I correct and should just fix my code? :)
(And for the curious, no, it's not a keylogger. It is for a very size limited(executable size <= 256 bytes) demoscene product which requires user to be able to ESC out from the intro.)