cout << "Push 'ENTER' to continue";
while (GetAsyncKeyState(VK_RETURN) & 0x8000) {} // if enter is already pressed, wait for it to be released
while (!(GetAsyncKeyState(VK_RETURN) & 0x8000)) {} // wait for enter to be pressed
My question: when I press 'ENTER', I think that 'ENTER' stays in the buffer and it will be shown next time I want to write something to the console (using cin). How do I clean it? I've tried using cin.clear() and cin.ignore(1000, '\n'), but it does nothing that I want...
You are correct: GetAsyncKeyState() does not modify the input buffer.
However, you still have a problem. The current state of the input buffer does not necessarily match the return value of GetAsyncKeyState().
However, you are thinking about this a little wrong. This kind of code assumes that there must be a human sitting at the PC, and that he is waiting on you to provide more input. As a result, you must clear the input buffer.