◄Up► ◄Contents► ◄Index► ◄Back► ─────Run-Time Library─────────────────────────────────────────────────────── /* 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; } } } -♦-