Mail Archives: djgpp/1998/02/22/21:11:17
Date: | Sun, 22 Feb 1998 21:09:30 -0500 (EST)
|
Message-Id: | <199802230209.VAA23206@delorie.com>
|
From: | DJ Delorie <dj AT delorie DOT com>
|
To: | spyder AT binary DOT net
|
CC: | djgpp AT delorie DOT com
|
In-reply-to: | <Pine.BSF.3.96.980222192549.18117B-100000@ravine.binary.net>
|
| (message from Daryl Johnson on Sun, 22 Feb 1998 19:35:56 -0600)
|
Subject: | Re: Need help with timer function
|
> I am creating a program that administers a test to an individual. The test
> is timed. The problem I am having is with getch(). Even when the timer has
I think you want something like this (untested). This is similar to
yours, but note the use of kbhit(), which tells you *if* a key has
been hit. Note also the use of __dpmi_yield() to avoid using 100% of
the CPU. You may want to look up getkey() and getxkey() as alternates
to getch(), depending on your needs.
#include <time.h>
#include <dpmi.h>
#include <pc.h>
#include <conio.h>
int timed_getch(int seconds)
{
time_t start, end;
time(&start);
while (1) {
time(&end_time);
if (end_time - start_time > seconds) return -1;
if (kbhit()) return getch();
__dpmi_yield();
}
}
- Raw text -