Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ReadConsoleInput() making console game jerky 1

Status
Not open for further replies.

serpento

Programmer
Jun 16, 2002
92
GB
I am trying to make a snakes game in the cosole window that uses the
following code to take keyboard input:

INPUT_RECORD InputRecord;
DWORD Events=0;

ReadConsoleInput(stdIH, &InputRecord, 1, &Events);

if(InputRecord.EventType == KEY_EVENT &&
InputRecord.Event.KeyEvent.bKeyDown)
{
if(InputRecord.Event.KeyEvent.wVirtualKeyCode == VK_RIGHT)
{
setPos(0,0);
cout << &quot;Right!&quot;;
}
}

FlushConsoleInputBuffer(stdIH);

It works fine as in when I press right it prints &quot;Right!&quot;, but when I
don't press anything it often pauses for several seconds at the
&quot;ReadConsoleInput(stdIH, &InputRecord, 1, &Events);&quot; line, making my
snake animation very jerky.
Anyone know how I could fix this?
-Ed ;-)

________________________________
Destiny is not a matter of chance; it is a matter of choice.
 
Ed,

From the MSDN library:

(ReadConsoleInput): The function does not return until at least one input record has been read.

I suggest you use PeekConsoleInput instead: If no data is available, the function returns immediately.
Marcel
 
Thanks! It works perfect now, I'll have a look in the MSDN thingie myself next time before pestering you. -Ed ;-)

________________________________
Destiny is not a matter of chance; it is a matter of choice.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top