I don't have an actual problem I'm working on, this is more a question of design decisions. I find that there are so many different things I work on where reading a
_kbhit() is amazingly useful but I can't find (read: there isn't) any functionality like that in the C++ standard.
- Example: Have a camera continuously running (and updating an on-screen window) until you hit the "escape" character.
- Example: Pressing F11 in firefox to maximize the window.
- Example: Pressing the W key in any FPS game to move forwards
All of these read the keyboard without pressing [enter] between each read. How the devil is that accomplished? Under windows I use
getch() in a continuous loop running in its own thread. I'm not sure if that's a good idea performance-wise, but most of the software I write that runs in an OS isn't very time critical (It's mostly command-line UIs that interface with the embedded systems that I develop).
The reason I'm asking is because a friend has asked me to help him write a UI for a system - and the UI has to run under Linux. I have no idea where to start and rather than turn him down, I thought I'd instead ask you guys: How do you read a keyboard hit without calling a conio.h function?