HPlogo MPE/iX Developer's Kit Reference Manual Volume 2: HP 3000 MPE/iX Computer Systems > Chapter 4 CURSES

getch wgetch mvgetch mvwgetch ungetch

» 

Technical documentation

Complete book in PDF
» Feedback

 » Table of Contents

 » Index

The getch, wgetch, mvgetch, mvwgetch, and ungetch routines are used to get a character from the keyboard.

Syntax

   #include <curses.h>



   int getch();

   int wgetch (WINDOW *win);



   int mvgetch(int y, int x);

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



   int ungetch(int ch);

Parameters

ch

The character to be put back in the input queue for the next call to getch().

x

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

y

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

win

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

Return Values

OK

Successful completion.

ERR

An error occurred. The nodelay() or wtimeout(0) routine is set, and no input is ready.

Description

The getch() and wgetch() routines get a character from the terminal associated with the window stdscror window win, respectively. The mvgetch() and mvwgetch() routines 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 wrefresh(), getch() calls wrefresh() to update the window before the next character is read.

The setting of certain routines affects how getch() works. For example, if cbreak() is set, characters typed by the user are immediately processed. If halfdelay() 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 wtimeout(). 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 returns). If nodelay() 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() has been set.

If keypad handling is enabled (keypad() 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 interbyte 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 interbyte timer is not set.

NOTE: The ESCAPE key is typically a prefix key used with function keys. Since prefix keys used with function keys should not be used as a single character, ensure that you do not use the ESCAPE key as a single character.

Table 4-6 “Constant Values for Function Keys” shows a list of tokens for the function keys that are returned by getch() if keypad handling is enabled. (Some terminals may not support all tokens.)

Table 4-6 Constant Values for Function Keys

ConstantDescription
KEY_BREAKBreak key
KEY_DOWNThe down arrow key
KEY_UPThe up arrow key
KEY_LEFTThe left arrow key
KEY_RIGHTThe right arrow key
KEY_HOMEHome key
KEY_BACKSPACEBackspace
KEY_F0Function keys. Space for 64
KEY_F(n)(KEY_F0+(n)) keys is reserved
KEY_DLDelete line
KEY_ILInsert line
KEY_DCDelete character
KEY_ICInsert char or enter insert mode
KEY_EICExit insert char mode
KEY_CLEARClear screen
KEY_EOSClear to end of screen
KEY_EOLClear to end of line
KEY_SFScroll 1 line forward
KEY_SRScroll 1 line backwards
KEY_NPAGENext page
KEY_PPAGEPrevious page
KEY_STABSet tab
KEY_CTABClear tab
KEY_CATABClear all tabs
KEY_ENTEREnter or send
KEY_SRESETSoft (partial) reset
KEY_RESETReset or hard reset
KEY_PRINTPrint or copy
KEY_LLHome down or bottom (lower left)
KEY_A1Upper left of keypad
KEY_A3Upper right of keypad
KEY_B2Center of keypad
KEY_C1Lower left of keypad
KEY_C3Lower right of keypad
KEY_BTABBack tab
KEY_BEGBeginning key
KEY_CANCELCancel key
KEY_CLOSEClose key
KEY_COMMANDCmd (command) key
KEY_COPYCopy key
KEY_CREATECreate key
KEY_ENDEnd key
KEY_EXITExit key
KEY_FIND Find key
KEY_HELP Help key
KEY_MARKMark key
KEY_MESSAGEMessage key
KEY_MOVEMove key
KEY_NEXTNext object key
KEY_OPENOpen key
KEY_OPTIONSOptions key
KEY_PREVIOUSPrevious object key
KEY_REDORedo key
KEY_REFERENCERef(erence) key
KEY_REFRESHRefresh key
KEY_REPLACEReplace key
KEY_RESTARTRestart key
KEY_RESUMEResume key
KEY_SAVESave key
KEY_SBEGShifted beginning key
KEY_SCANCELShifted cancel key
KEY_SCOMMANDShifted command key
KEY_SCOPYShifted copy key
KEY_SCREATEShifted create key
KEY_SDCShifted delete char key
KEY_SDLShifted delete line key
KEY_SELECTSelect key
KEY_SENDShifted end key
KEY_SEOLShifted clear line key
KEY_SEXITShifted exit key
KEY_SFINDShifted find key
KEY_SHELPShifted help key
KEY_SHOMEShifted home key
KEY_SICShifted input key
KEY_SLEFTShifted left key
KEY_SMESSAGESShifted messages key
KEY_SMOVEShifted move key
KEY_SNEXTShifted next key
KEY_SOPTIONS Shifted options key
KEY_SPREVIOUS Shifted previous key
KEY_SPRINTShifted print key
KEY_SREDOShifted redo key
KEY_SREPLACEShifted replace key
KEY_SRIGHTShifted right key
KEY_SRSUMEShifted resume key
KEY_SSAVEShifted save key
KEY_SSUSPENDShifted suspend key
KEY_SUNDOShifted undo key
KEY_SUSPENDSuspend key
KEY_UNDOUndo key

 

The ungetch() routine delays processing of ch until the next call to getch().

NOTE: The getch(), mvgetch(), and mvwgetch() routines are macros.

Implementation Considerations

The getch(), mvgetch(), mvwgetch(), and wgetch() routines are identical to XPG/3. The ungetch() routine is a UNIX System V implementation.

See Also

cbreak(), echo(), keypad(), halfdelay(), nodelay(), notimeout(), raw(), wtimeout()

Portability

The getch(), mvgetch(), mvwgetch(), and wgetch() routines conform to HP-UX, UNIX System V, and XPG/3. The ungetch() routine conforms to UNIX System V.

Feedback to webmaster