[Previous]
[Contents]
[Next]

getch()

get the next available keystroke from the console

Synopsis:

#include <conio.h>
int getch( void );

Description:

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.

Returns:

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.

Examples:

#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 );
  }

Classification:

WATCOM

Safety:
Interrupt handler No
Signal handler Yes
Thread Yes

See also:

getche(), kbhit(), putch(), ungetch()


[Previous]
[Contents]
[Next]