[Previous]
[Contents]
[Next]

getche()

get the next keystroke from the console, and echo it

Synopsis:

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

Description:

The getche() function obtains the next available keystroke from the console. It waits until a keystroke is available. That character is echoed on the screen at the position of the cursor (use getch when you don't want to echo the keystroke).

The kbhit function can be used to determine if a keystroke is available.

Returns:

The value of the keystroke (or character), or EOF if 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 getche() returns a value for the extended function.

Examples:

#include <stdio.h>
#include <conio.h>

void main()
  {
    int c;

    printf( "Press any key\n" );
    c = getche();
    printf( "You pressed %c(%d)\n", c, c );
  }

Classification:

WATCOM

Safety:
Interrupt handler No
Signal handler Yes
Thread Yes

See also:

getch(), kbhit(), putch(), ungetch()


[Previous]
[Contents]
[Next]