[console] Add a timeout parameter to getkey()

Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown
2011-03-07 19:33:50 +00:00
parent 2969a8567f
commit 9d633bdc71
7 changed files with 13 additions and 16 deletions

View File

@@ -35,13 +35,13 @@ FILE_LICENCE ( GPL2_OR_LATER );
/**
* Read character from console if available within timeout period
*
* @v timeout Timeout period, in ticks
* @v timeout Timeout period, in ticks (0=indefinite)
* @ret character Character read from console
*/
int getchar_timeout ( unsigned long timeout ) {
static int getchar_timeout ( unsigned long timeout ) {
unsigned long start = currticks();
while ( ( currticks() - start ) < timeout ) {
while ( ( timeout == 0 ) || ( ( currticks() - start ) < timeout ) ) {
step();
if ( iskey() )
return getchar();
@@ -53,6 +53,7 @@ int getchar_timeout ( unsigned long timeout ) {
/**
* Get single keypress
*
* @v timeout Timeout period, in ticks (0=indefinite)
* @ret key Key pressed
*
* The returned key will be an ASCII value or a KEY_XXX special
@@ -60,11 +61,11 @@ int getchar_timeout ( unsigned long timeout ) {
* will return "special" keys (e.g. cursor keys) as a series of
* characters forming an ANSI escape sequence.
*/
int getkey ( void ) {
int getkey ( unsigned long timeout ) {
int character;
unsigned int n = 0;
character = getchar();
character = getchar_timeout ( timeout );
if ( character != ESC )
return character;