Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

cbreak(3XC)

echo(3XC)

halfdelay(3XC)

keypad(3XC)

nodelay(3XC)

notimeout(3XC)

raw(3XC)

timeout(3XC)

getch(3XC)

NAME

getch, wgetch, mvgetch, mvwgetch − get a single-byte character from terminal

SYNOPSIS

#include <curses.h>

int getch(void);

int wgetch (WINDOW ∗win);

int mvgetch(int y, int x);

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

ARGUMENTS

winIs a pointer to the window associated with the terminal from which the character is to be read. 

yIs the y (row) coordinate for the position of the character to be read. 

xIs the x (column) coordinate for the position of the character to be read. 

DESCRIPTION

The getch() and wgetch() functions get a single-byte character from the terminal associated with the window stdscr or window win, respectively.  The mvgetch() and mvwgetch() functions move the cursor to the position specified in stdscr or win, respectively, then get a character. 

If the window is not a pad and has been changed since the last call to refresh(3XC), getch() calls refresh() to update the window before the next character is read. 

The setting of certain functions affects the behavior of the getch() set of functions.  For example, if cbreak(3XC) is set, characters typed by the user are immediately processed.  If halfdelay(3XC) is set, getch() waits until a character is typed or returns ERR if no character is typed within the specified timeout period.  This timeout can also be specified for individual windows with the delay parameter of timeout(3XC).  A negative value waits for input; a value of 0 returns ERR if no input is ready; a positive value blocks until input arrives or the time specified expires (in which case, ERR is returned).  If nodelay(3XC) is set, ERR is returned if no input is waiting; if not set, getch() waits until input arrives.  Each character will be echoed to the window unless noecho(3XC) has been set. 

If keypad handling is enabled ( keypad(3XC) is TRUE), the token for the function key is returned.  If a character is received that could be the beginning of a function key (for example, ESC), an inter-byte timer is set.  If the remainder of the sequence is not received before the time expires, the character is passed through; otherwise, the value of the function key is returned.  If notimeout() is set, the inter-byte timer is not used. 

The ESC key is typically a prefix key used with function keys and should not be used as a single character. 

The following is a list of tokens for function keys that are returned by the getch() set of functions if keypad handling is enabled (some terminals may not support all tokens). 

Constant Values for Function Keys

Constant Description
KEY_BREAK Break key
KEY_DOWN The down arrow key
KEY_UP The up arrow key
KEY_LEFT The left arrow key
KEY_RIGHT The right arrow key
KEY_HOME Home key
KEY_BACKSPACE Backspace
KEY_F0 Function keys.  Space for 64
KEY_F(n) (KEY_F0+(n)) key is reserved
KEY_DL Delete line
KEY_IL Insert line
KEY_DC Delete character
KEY_IC Insert char or enter insert mode
KEY_EIC Exit insert char mode
KEY_CLEAR Clear screen
KEY_EOS Clear to end of screen
KEY_EOL Clear to end of line
KEY_SF Scroll 1 line forward
KEY_SR Scroll 1 line backwards
KEY_NPAGE Next page
KEY_PPAGE Previous page
KEY_STAB Set tab
KEY_CTAB Clear tab
KEY_CATAB Clear all tabs
KEY_ENTER Enter or send
KEY_SRESET Soft (partial) reset
KEY_RESET Reset or hard reset
KEY_PRINT Print or copy
KEY_LL Home down or bottom (lower left)
KEY_A1 Upper left of keypad
KEY_A3 Upper right of keypad
KEY_B2 Center of keypad
KEY_C1 Lower left of keypad
KEY_C3 Lower right of keypad
KEY_BTAB Back tab
KEY_BEG Beginning key
KEY_CANCEL Cancel key
KEY_CLOSE Close key
KEY_COMMAND Cmd (command) key
KEY_COPY Copy key
KEY_CREATE Create key

(Continued)

Constant Description
KEY_END End key
KEY_EXIT Exit key
KEY_FIND Find key
KEY_HELP Help key
KEY_MARK Mark key
KEY_MESSAGE Message key
KEY_MOVE Move key
KEY_NEXT Next object key
KEY_OPEN Open key
KEY_OPTIONS Options key
KEY_PREVIOUS Previous object key
KEY_REDO Redo key
KEY_REFERENCE Ref(erence) key
KEY_REFRESH Refresh key
KEY_REPLACE Replace key
KEY_RESTART Restart key
KEY_RESUME Resume key
KEY_SAVE Save key
KEY_SBEG Shifted beginning key
KEY_SCANCEL Shifted cancel key
KEY_SCOMMAND Shifted command key
KEY_SCOPY Shifted copy key
KEY_SCREATE Shifted create key
KEY_SDC Shifted delete char key
KEY_SDL Shifted delete line key
KEY_SELECT Select key
KEY_SEND Shifted end key
KEY_SEOL Shifted clear line key
KEY_SEXIT Shifted exit key
KEY_SFIND Shifted find key
KEY_SHELP Shifted help key
KEY_SHOME Shifted home key
KEY_SIC Shifted input key
KEY_SLEFT Shifted left key
KEY_SMESSAGES Shifted messages key
KEY_SMOVE Shifted move key
KEY_SNEXT Shifted next key
KEY_SOPTIONS Shifted options key
KEY_SPREVIOUS Shifted previous key
KEY_SPRINT Shifted print key
KEY_SREDO Shifted redo key

(Continued)

Constant Description
KEY_SREPLACE Shifted replace key
KEY_SRIGHT Shifted right key
KEY_SRSUME Shifted resume key
KEY_SSAVE Shifted save key
KEY_SSUSPEND Shifted suspend key
KEY_SUNDO Shifted undo key
KEY_SUSPEND Suspend key
KEY_UNDO Undo key

RETURN VALUES

On success, these function return OK.  Otherwise, they return ERR. 

ERRORS

None

SEE ALSO

cbreak(3XC), echo(3XC), halfdelay(3XC), keypad(3XC), nodelay(3XC), notimeout(3XC), raw(3XC), timeout(3XC)

SunOS 5.6  —  Last change: 1 Jun 1996

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