Programming Guide |
Tests whether a key is typed ahead
int sm_keyhit(int interval);
interval
- Specifies in tenths of seconds how long to wait before it checks whether the user pressed a key. The exact length of the wait depends on the granularity of the system clock and on the hardware and operating system.
- 1 A key was typed ahead, or pressed during the
interval-
specified period.
sm_keyhit
checks whether a key has already been pressed. If a key has been pressed, it returns 1 immediately. Otherwise, it waits the specified interval. If a key is pressed during the interval the function returns 1; otherwise, it returns 0. The key, if any is struck, is not read in and is available to the usual keyboard input functions.If the operating system does not support reads with timeout, this function ignores the interval and only returns 1 if a key has been typed ahead.
Panther calls timeout and timer functions and updates the date/time display of fields with System Update set to Yes during calls to this function.
#include <smdefs.h>
#include <smkeys.h>
/* The following code adds one asterisk per second to
* a danger bar, until somebody presses EXIT. */
static char *danger_bar = "***********************";
int k;
sm_d_msg_line
("You have 25 seconds to find the EXIT key.", WHITE);
/* Clear the danger bar area
sm_do_region(5, 10, 25, WHITE, ""); */
for (k = 1; k <= 25; ++k)
{
sm_flush();
}
if (sm_keyhit(10))
{
if (sm_getkey() == EXIT)
break;
}
sm_do_region(5, 10, k, WHITE, danger_bar);
if (k <= 25)
sm_d_msg_line("%BCongratulations! you win!");
else
sm_ferr_reset(0, "Sorry, you lose.");