[ale] keystrokes
Jacob Langseth
dragon at cc.gatech.edu
Wed Oct 30 02:07:08 EST 1996
} Is there any shell command in bash that will allow me to grab keystrokes other
} than read. I would like to do a read command but give a time limit of
} 60 seconds. Ne1 know how. Or does ne1 have a C program that will take
} the time length on the command line and return the input on STDOUT?
This _should_ do it... however, getchar() seems to block until it gets a
newline, both under SunOS and linux (why? anyone?).
If you're interested in getting everything they typed up until <RETURN>
anyway (as opposed to a single key), it'll work just fine. Just change
the putchar( getchar() ); line to
int c;
while((c = getchar()) != '\n')
putchar( c );
-JwL
/* wait_for_key.c 96.10.30 Jacob Langseth <dragon at cc.gatech.edu> */
#include <stdio.h>
#include <unistd.h>
int main( int argc, char **argv )
{
unsigned int uiTimeout=0;
char *p;
if (argc != 2) {
printf( "USAGE: wait_for_key timeout\n" );
return( -1 );
}
p = *(++argv);
while( *p ) {
if ((*p < '0') || (*p > '9')) {
printf( "irk! timeout should be a number >= 0\n" );
return( -1 );
}
uiTimeout = 10 * uiTimeout + *p - '0';
p++;
}
alarm( uiTimeout );
putchar( getchar() );
alarm( 0 );
return( 0 );
}
--
/ "Meddle not in the affairs of dragons, for \
*}=={*}>======- thou art crunchy and go well with ketchup." -======<{*}=={*
\ <dragon at cc.gatech.edu> /
Musashi - - -=- Finger for PGP key -=- - - Musashi
More information about the Ale
mailing list