H
hugo27
June 28, 2004
I'm interested in finding a way to test the keyboard buffer
for MT/Not MT. Tried kbhit() in system.h but it didn't do
what I thought it would from reading the literature.
Samples: Compiler Docs said,
"Detects whether a keypress is available for reading."
Herbert Schildt said,
"If the user has pressed a key, this function returns
true(non-0), but does not read the character.
If no keystroke is pending, kbhit() returns false (0)."
Here is the test code. kbhit() executes between two
getchar() calls.
#include <stdio.h>
#include <system.h>
void main() {
int ig1=0, ig2=0, ik=-1;
ig1 = getchar();
ik = kbhit();
ig2 = getchar();
getchar();
printf("ig1=%d, ik=%d, ig2=%d", ig1,ik,ig2);
return;
}
At runtime, I pressed aAEnter, so that 'A' and '\n'
were in buffer when kbhit() executed, yet ik returned
as 0.
Where else would a keystroke be "waiting" or "available"
except in the buffer? If kbhit() does not look at the
buffer, what does it look at?
I'm interested in finding a way to test the keyboard buffer
for MT/Not MT. Tried kbhit() in system.h but it didn't do
what I thought it would from reading the literature.
Samples: Compiler Docs said,
"Detects whether a keypress is available for reading."
Herbert Schildt said,
"If the user has pressed a key, this function returns
true(non-0), but does not read the character.
If no keystroke is pending, kbhit() returns false (0)."
Here is the test code. kbhit() executes between two
getchar() calls.
#include <stdio.h>
#include <system.h>
void main() {
int ig1=0, ig2=0, ik=-1;
ig1 = getchar();
ik = kbhit();
ig2 = getchar();
getchar();
printf("ig1=%d, ik=%d, ig2=%d", ig1,ik,ig2);
return;
}
At runtime, I pressed aAEnter, so that 'A' and '\n'
were in buffer when kbhit() executed, yet ik returned
as 0.
Where else would a keystroke be "waiting" or "available"
except in the buffer? If kbhit() does not look at the
buffer, what does it look at?