JH> PH> Another way would be to check the time (using
JH> PH> standard C time functions or system BIOS functions or
JH> PH> reading I/O ports directly) within your program's
JH> PH> main loop, and update the clock's display whenever
JH> PH> the time changes.
JH> The prob with this method, is that if there is a "wait
JH> for keypress" in the loop, then the clock stops untill
JH> the next keypress.
You have to take that into account and construct your getkey
function accordingly. In this example, you can pass a filter
string, or NULL, and whether to wait or return immediately if
no key has been pressed. The update_clock() routine should be
separate so it may be called from various places, or not
called if the display is one where it is not wanted.
One could also make the call to update_clock() dependent
upon a variable as well.
int getkey_clock(char *filter, int wait)
{
int result = 0;
do {
if(kbhit())
{
result = (0 == (result = getch())) ? -getch() : result;
if(filter && !strchr(filter, result))
result = 0;
}
update_clock();
} while(!result && wait)
return result;
}
> ] Conspiracy? There's no conspiracy. Go ahead. Ask anyone.....
---
---------------
* Origin: *YOPS ]I[* 8.4 GIG * RA/FD/FE * Milwaukee, WI (1:154/750)
|