I need to clear/reset an input record I'm using within a loop. Normally, with a basic struct/type such as int, I would do something like the following:
This way, if nothing were assigned to x, but x was 2 in the preceeding iteration, it wouldn't re-execute case 2.
x = 0;
cin >> x;
How could I do the same with an input record?
Found it. FlushConsoleInputBuffer(HANDLE hConsoleInput);
I should have implemented that before I posted it. That cleans out the buffer, but the record still exists.
So I cheated:
'i' is just a character that I don't use in my conditionals.
InRec.Event.KeyEvent.uChar.AsciiChar = 'i';
and yes, flush the input buffer if it fails.
if (cin >> x)
Some standard ways are mentioned here:
Difficult to say without seeing your actual code. You could change the EventType to an invalid value if you're looking at that, or the key value to one your notchecking for.
Really, you should not be structuring your code that way, you should either be waiting for an event to occur, or checking to see if there are any events in the queue. In either case the situation you describe would not occur.
I actually am checking for events in queue, it just does it in every iteration, so the user can enter any key value I check for at any point in any iteration, and have the same outcome. I just don't want to process any key value twice.
I got it working with the cheat I posted earlier (changing the key value to one I don't check for).
I would, though, like to have it done more thoroughly, meaning a more conventional way to reset the input record.
The code is pretty massive, though I could post a link to it if you want to take a look.
Oh yeah, Hammer, I think you missed the point. The code I posted was just an example of my problem with int instead of INPUT_RECORD.