I believe this is a very simple question, but I can\'t find a simple answer to it. I have an infinite loop, e.g. while(1)
, for(;;)
, and I need to b
There is no "keyboard" in C++. You only have an opaque input data stream which your terminal populates occasionally with its own keyboard input. This is almost always a buffered, editable line-wise input, so you have no way of knowing when any given key was pressed.
You need a platform-specific method to communicate directly with your terminal on a lower level. One such library, fairly wide-spread and portable, is ncurses
(a compatible Windows variant exists). Portable graphical application frameworks such as SDL and Allegro also provide raw keyboard handling.