getkey.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 FILE_LICENCE ( GPL2_OR_LATER );
00020
00021 #include <ctype.h>
00022 #include <console.h>
00023 #include <gpxe/process.h>
00024 #include <gpxe/keys.h>
00025 #include <gpxe/timer.h>
00026
00027
00028
00029
00030
00031
00032
00033 #define GETKEY_TIMEOUT ( TICKS_PER_SEC / 4 )
00034
00035
00036
00037
00038
00039
00040
00041 static int getchar_timeout ( unsigned long timeout ) {
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 }
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063 int getkey ( void ) {
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 }