Hi all you hardcore coders and everyone else.
I'm a beginner programmer, so forgive me if this is a stupid question.
I'd like to be able to check if the user has pressed a key since I
flushed the keyboard buffer. But the only thing I can find is a function
kbhit(), which I believe is a Borland only component and not really a
part of ANSI C. kbhit() is not supported in any of my standard #include
files.
getch() stops execution and waits for user to press a key and I don't
want to do that.
I need to make something like this:
flush_keyboard_buffer();
while (FOREVER)
{
..
..
..
if ( is_keyboard_buffer_empty() )
{
ch = getch();
if ( ch == ESC_KEY ) break;
}
..
..
..
}
I don't know how to make: flush_keyboard_buffer()
is_keyboard_buffer_empty()
I don't know if I can use getch() like i do in the code above.
An even better and more versatile solution would be, if i'm able to get
a key's current state. This would truely make me a happy camper.
The scenario is pretty much described in the code snippet below.
I will be forever grateful if someone can help me make the function:
int key_pressed(int keycode)
The function should return 1 if the key described by keycode is
currently pressed, and 0 if the key is not pressed. It would be extra
nice if i'm able to catch the state of SHIFT, ALT, CTRL, etc.
It'll be used in code similar to the code snippet below.
while (FOREVER)
{
..
..
if (key_pressed(ESC_KEY)) break;
..
..
}
If you have an even better solution, please don't hesitate to write. I
dying to get this code implemented.
Thank you very much in advance
/A\ndreas