getche

Obtains the next available keystroke from the current screen and echoes the keystroke on the screen

Local Servers:blocking
Remote Servers:N/A
Classification:Other
Service:Device I/O

Syntax

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

Return Values

getche returns a value of EOF when an error is detected. Otherwise, the getche function returns the value of the keystroke (or character).

When the keystroke represents an extended key (for example, a function key, a cursor-movement key, or the Alt key with a letter or a digit), a value of 0 is returned, and the next call to getche returns a value for the extended function. When an error occurs, errno is set.

Remarks

The getche function reads from the current screen. The function waits until a keystroke is available. That character is echoed on the screen at the position of the cursor. Use the getch function when it is not desired to echo the keystroke.

Use the kbhit function to determine if a keystroke is available.

See Also

getch, kbhit, ungetch

Example

  #include <stdlib.h>  
  #include <nwconio.h>  
   
  main ()  
  {  
     int   keyStroke;  
     while((keyStroke = getche()) != ’0’)  
        printf ("%d\r\n",keyStroke);  
  }