Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

cbreak(3)

keypad(3)

nodelay(3)

noecho(3)

getch(3)  —  Subroutines

Digital

NAME

getch, mvgetch, mvwgetch, wgetch − read character

SYNOPSIS

#include <curses.h>

int getch()

int wgetch(win)
WINDOW ∗win;

int mvgetch(y, x)
int y, x;

int mvwgetch(win, y, x)
WINDOW ∗win;
int y, x;

DESCRIPTION

The getch routine reads a character from the terminal associated with the default window. 

The wgetch routine reads a character from the terminal associated with the specified window. 

The routine mvgetch reads a character from the terminal associated with the default window at the specified position. 

The routine mvwgetch reads a character from the terminal associated with the specified window at the specified position. 

The following information applies to all the routines.  In nodelay mode, if there is no input waiting, the integer ERR is returned. In delay mode, the program waits until the system passes text through to the program.  Usually the program will restart after one character or after the first newline, but this depends on how cbreak is set. The character will be echoed on the designated window unless noecho has been set. 

If keypad is TRUE and a function key is pressed, the token for that function key is returned instead of the raw characters.  Possible function keys are defined in the <curses.h> header file with integers beginning with 0401.  The function key names begin with KEY_. 

If a character is received that could be the beginning of a function key (such as escape), curses sets a timer.  If the remainder of the sequence does not come within the designated time, the character will be passed through; otherwise the function key value is returned.  Consequently, there may be a delay after a user presses the escape key before the escape is returned to the program. 

Using the escape key for a single character function is discouraged. 

The routines getch, mvgetch, and mvwgetch are macros. 

RETURN VALUES

Upon successful completion, the getch, mvgetch, and wgetch functions return the character read. 

If delay mode is in effect and no data is available, ERR is returned. 

RELATED INFORMATION

cbreak(3), keypad(3), nodelay(3), noecho(3)

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026