-
Input Record
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:
Code:
int x;
while(true)
{
x = 0;
cin >> x;
switch(x)
{
case 1:
break;
case 2:
break;
}
}
This way, if nothing were assigned to x, but x was 2 in the preceeding iteration, it wouldn't re-execute case 2.
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:
Code:
InRec.Event.KeyEvent.uChar.AsciiChar = 'i';
'i' is just a character that I don't use in my conditionals.
-
Code:
if (cin >> x)
{
switch(x)
.....
}
and yes, flush the input buffer if it fails.
Some standard ways are mentioned here:
http://faq.cprogramming.com/cgi-bin/...&id=1043284392
-
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.