This is indeed OS dependent, but probabilities are that you use Windows.
First, you'll need to include :
#include <Windows.h>
It gives you access to the function GetAsyncKeyState, and to Windows' key macros (list of Windows' key macros).
You'll also need the Most Significant Bit to evaluate key press ; just initialize it as a const in your code :
const unsigned short MSB = 0x8000;
Finally, let's put all together in a function :
bool listenKeyPress(short p_key)
{
//if p_key is pushed, the MSB will be set at 1
if (GetAsyncKeyState(p_key) & MSB)
{
return true;
}
else return false;
}
//Example of a call to this function to check if up enter is pressed :
listenKeyPress(VK_RETURN)
Then your while loop can be typed either :
while (!listenKeyPress(VK_ENTER))
{
}
or
bool quit = false;
while (!quit)
{
if (listenKeyPress(VK_ENTER) || listenKeyPress(VK_ESCAPE)
quit = true;
}
There you go!