getkey.c File Reference

Special key interpretation. More...

#include <ctype.h>
#include <console.h>
#include <gpxe/process.h>
#include <gpxe/keys.h>
#include <gpxe/timer.h>

Go to the source code of this file.

Defines

#define GETKEY_TIMEOUT   ( TICKS_PER_SEC / 4 )

Functions

 FILE_LICENCE (GPL2_OR_LATER)
static int getchar_timeout (unsigned long timeout)
 Read character from console if available within timeout period.
int getkey (void)
 Get single keypress.


Detailed Description

Special key interpretation.

Definition in file getkey.c.


Define Documentation

#define GETKEY_TIMEOUT   ( TICKS_PER_SEC / 4 )

Definition at line 33 of file getkey.c.

Referenced by getkey().


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER   ) 

static int getchar_timeout ( unsigned long  timeout  )  [static]

Read character from console if available within timeout period.

Parameters:
timeout Timeout period, in ticks
Return values:
character Character read from console

Definition at line 41 of file getkey.c.

References currticks(), getchar(), iskey(), and step().

Referenced by getkey().

00041                                                      {
00042         unsigned long expiry = ( currticks() + timeout );
00043 
00044         while ( currticks() < expiry ) {
00045                 step();
00046                 if ( iskey() )
00047                         return getchar();
00048         }
00049 
00050         return -1;
00051 }

int getkey ( void   ) 

Get single keypress.

Return values:
key Key pressed
The returned key will be an ASCII value or a KEY_XXX special constant. This function differs from getchar() in that getchar() will return "special" keys (e.g. cursor keys) as a series of characters forming an ANSI escape sequence.

Definition at line 63 of file getkey.c.

References ESC, getchar(), getchar_timeout(), GETKEY_TIMEOUT, isdigit, and KEY_ANSI.

Referenced by login_ui(), main_loop(), pxe_menu_prompt_and_select(), pxe_menu_select(), and readline().

00063                     {
00064         int character;
00065         unsigned int n = 0;
00066 
00067         character = getchar();
00068         if ( character != ESC )
00069                 return character;
00070 
00071         while ( ( character = getchar_timeout ( GETKEY_TIMEOUT ) ) >= 0 ) {
00072                 if ( character == '[' )
00073                         continue;
00074                 if ( isdigit ( character ) ) {
00075                         n = ( ( n * 10 ) + ( character - '0' ) );
00076                         continue;
00077                 }
00078                 if ( character >= 0x40 )
00079                         return KEY_ANSI ( n, character );
00080         }
00081 
00082         return ESC;
00083 }


Generated on Tue Apr 6 20:01:14 2010 for gPXE by  doxygen 1.5.7.1