get the next available keystroke from the console
#include <conio.h> int getch( void );
The getch() function obtains the next available keystroke from the console. Nothing is echoed on the screen (the function getche() will echo the keystroke, if possible). When no keystroke is available, the function waits until a key is depressed.
The kbhit() function can be used to determine if a keystroke is available.
The value of the keystroke (or character), or EOF when an error is detected.
When the keystroke represents an extended function key (for example, a function key, a cursor-movement key or the ALT key with a letter or a digit), 0xff is returned, and the next call to getch() returns a value for the extended function.
#include <stdio.h> #include <conio.h> void main() { int c; printf( "Press any key\n" ); c = getch(); printf( "You pressed %c(%d)\n", c, c ); }
WATCOM
Safety: | |
---|---|
Interrupt handler | No |
Signal handler | Yes |
Thread | Yes |
getche(), kbhit(), putch(), ungetch()