-
Buffer problem
alrighty im making this game kinda like snake. My problem is that i want to see if there is something in the keyboard buffer or not and not wait for the user to really push a key
f.e
Code:
int running = 1;
while(running)
{
char c=0;
int move;
somefucntionidontknow(c);
switch(c)
{
case 't':
goto(0,-1)
case 'g':
goto(0,1)
case 'f':
goto(-1,0)
case 'h':
goto(0,-1)
default
goto(2,2)
}
sleep(200);
}
goto would remember in what direction the head is and when it gets 2,2 go on in that direction. Problem is , if i use scanf() the computer waits till input if there isnt anything in the keyboard buffer. getch() does the same . I just want to check if a there is something in the buffer , if not go on without waiting. I thought about using threads which seems kinda hard in mingw (im doing this in C only no C++). Any suggestion or is threads my only option???
thank you for you attention if you made it this far :D
-
-
There is no way to help you without more information. We live in a computer world filled with different platforms and APIs.
In Windows you check for messages to see if keys are down. In DirectInput you can either poll the device or you can use buffered input. In DOS you would normally write your own keyboard interrupt handler which still works under XP but I do not recommend any type of DOS programming anymore.
-
thx for your replies
im using mingw (devc++)
hmmz i'll take a close look at the faq thingie but i know getch() this is not what am looking for :s I want the fctn to move on even if there hasnt been a key pushed
btw ill post a version of the game tommorow eve cause i got to go to work now