Mail Archives: djgpp/2002/05/17/14:31:38
Hi,
I'm using kbhit() and getkey() for simple user interaction
e.g. yes/no or "any key" questions. But this is very DJGPP
specific. Is there a way to write these things more portable,
especially for UNIX environments?
There are 2 main functionalities:
1) empty the keyboard buffer:
while(kbhit())
{
getkey();
}
2) wait for and read a single key
x = getkey();
A typical application of this might look like:
int yes_no(char *question)
{
int key = -1;
int count = 100;
while(kbhit())
{
getkey();
}
if(question)
{
printf("%s (Y/N)\n", question);
}
else
{
printf("(Y/N)\n");
}
while(count--)
{
key = getkey();
switch(key)
{
case 'y':
case 'Y':
return 1;
case 'n':
case 'N':
return 0;
default:
break;
}
}
return -1;
} /* End yes_no() */
Any brilliant ideas?
Regards,
Tony
--
GMX - Die Kommunikationsplattform im Internet.
http://www.gmx.net
- Raw text -