Mail Archives: djgpp/1997/06/20/21:06:17
James MacDonald (trill AT Xnetbook DOT demon DOT co DOT uk) wrote:
: Is it possible to have a three second delay in which time F1 can be
: pressed (like INKEY/INKEY$ in BBC BASIC)?
How about this:
#include <conio.h>
#include <time.h>
int inkey(int a)
/* IIRC a is measured in centiseconds, so that's what I've done here */
{
int start;
if (a<0)
return 0; /* you'd need to use Allegro or similar to do these */
else {
start=clock();
while ((!kbhit())&&(clock()-start<a*CLOCKS_PER_SEC/100));
if (kbhit())
return (getch());
else
return 0; /* or was it -1? Can't remember... I think it was 0 for
false though */
}
}
I tried this, it seems to work as expected. In C I suppose INKEY and
INKEY$ are pretty much the same. If you're fussy about timing accuracy,
replace clock with uclock in both places and replace CLOCKS_PER_SEC with
UCLOCKS_PER_SEC, but refer to the warnings in the documentation for
uclock.
--
George Foot <mert0407 AT sable DOT ox DOT ac DOT uk>
Merton College, Oxford
- Raw text -