Important Notice
The pages on this site contain documentation for very old MS-DOS software,
purely for historical purposes.
If you're looking for up-to-date documentation, particularly for programming,
you should not rely on the information found here, as it will be woefully
out of date.
GETCH.C
◄Up► ◄Contents► ◄Index► ◄Back►
────────────────────────────────────────────────────────────────────────────
/* GETCH.C illustrates how to process ASCII or extended keys.
* Functions illustrated include:
* getch getche
*/
#include <conio.h>
#include <ctype.h>
#include <stdio.h>
void main()
{
int key;
/* Read and display keys until ESC is pressed. */
while( 1 )
{
/* If first key is 0, then get second extended. */
key = getch();
if( (key == 0) || (key == 0xe0) )
{
key = getch();
printf( "ASCII: no\tChar: NA\t" );
}
/* Otherwise, there's only one key. */
else
printf( "ASCII: yes\tChar: %c \t", isgraph( key ) ? key : ' ' );
printf( "Decimal: %d\tHex: %X\n", key, key );
/* Echo character response to prompt. */
if( key == 27)
{
printf( "Do you really want to quit? (Y/n) " );
key = getche();
printf( "\n" );
if( (toupper( key ) == 'Y') || (key == 13) )
break;
}
}
}