| 1 | '\" t
|
|---|
| 2 | .\"***************************************************************************
|
|---|
| 3 | .\" Copyright (c) 1998-2003,2005 Free Software Foundation, Inc. *
|
|---|
| 4 | .\" *
|
|---|
| 5 | .\" Permission is hereby granted, free of charge, to any person obtaining a *
|
|---|
| 6 | .\" copy of this software and associated documentation files (the *
|
|---|
| 7 | .\" "Software"), to deal in the Software without restriction, including *
|
|---|
| 8 | .\" without limitation the rights to use, copy, modify, merge, publish, *
|
|---|
| 9 | .\" distribute, distribute with modifications, sublicense, and/or sell *
|
|---|
| 10 | .\" copies of the Software, and to permit persons to whom the Software is *
|
|---|
| 11 | .\" furnished to do so, subject to the following conditions: *
|
|---|
| 12 | .\" *
|
|---|
| 13 | .\" The above copyright notice and this permission notice shall be included *
|
|---|
| 14 | .\" in all copies or substantial portions of the Software. *
|
|---|
| 15 | .\" *
|
|---|
| 16 | .\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
|
|---|
| 17 | .\" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
|
|---|
| 18 | .\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
|
|---|
| 19 | .\" IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
|
|---|
| 20 | .\" DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
|
|---|
| 21 | .\" OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
|
|---|
| 22 | .\" THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
|---|
| 23 | .\" *
|
|---|
| 24 | .\" Except as contained in this notice, the name(s) of the above copyright *
|
|---|
| 25 | .\" holders shall not be used in advertising or otherwise to promote the *
|
|---|
| 26 | .\" sale, use or other dealings in this Software without prior written *
|
|---|
| 27 | .\" authorization. *
|
|---|
| 28 | .\"***************************************************************************
|
|---|
| 29 | .\"
|
|---|
| 30 | .\" $Id: curs_getch.3x,v 1.29 2005/06/25 22:03:09 tom Exp $
|
|---|
| 31 | .TH curs_getch 3X ""
|
|---|
| 32 | .na
|
|---|
| 33 | .hy 0
|
|---|
| 34 | .SH NAME
|
|---|
| 35 | \fBgetch\fR,
|
|---|
| 36 | \fBwgetch\fR,
|
|---|
| 37 | \fBmvgetch\fR,
|
|---|
| 38 | \fBmvwgetch\fR,
|
|---|
| 39 | \fBungetch\fR,
|
|---|
| 40 | \fBhas_key\fR \- get (or push back) characters from \fBcurses\fR terminal keyboard
|
|---|
| 41 | .ad
|
|---|
| 42 | .hy
|
|---|
| 43 | .SH SYNOPSIS
|
|---|
| 44 | \fB#include <curses.h>\fR
|
|---|
| 45 | .PP
|
|---|
| 46 | \fBint getch(void);\fR
|
|---|
| 47 | .br
|
|---|
| 48 | \fBint wgetch(WINDOW *win);\fR
|
|---|
| 49 | .br
|
|---|
| 50 | \fBint mvgetch(int y, int x);\fR
|
|---|
| 51 | .br
|
|---|
| 52 | \fBint mvwgetch(WINDOW *win, int y, int x);\fR
|
|---|
| 53 | .br
|
|---|
| 54 | \fBint ungetch(int ch);\fR
|
|---|
| 55 | .br
|
|---|
| 56 | \fBint has_key(int ch);\fR
|
|---|
| 57 | .br
|
|---|
| 58 | .SH DESCRIPTION
|
|---|
| 59 | The \fBgetch\fR, \fBwgetch\fR, \fBmvgetch\fR and \fBmvwgetch\fR, routines read
|
|---|
| 60 | a character from the window.
|
|---|
| 61 | In no-delay mode, if no input is waiting, the value \fBERR\fR is returned.
|
|---|
| 62 | In delay mode, the program waits until the system
|
|---|
| 63 | passes text through to the program.
|
|---|
| 64 | Depending on the setting of \fBcbreak\fR,
|
|---|
| 65 | this is after one character (cbreak mode),
|
|---|
| 66 | or after the first newline (nocbreak mode).
|
|---|
| 67 | In half-delay mode,
|
|---|
| 68 | the program waits until a character is typed or the
|
|---|
| 69 | specified timeout has been reached.
|
|---|
| 70 | .PP
|
|---|
| 71 | Unless \fBnoecho\fR has been set,
|
|---|
| 72 | then the character will also be echoed into the
|
|---|
| 73 | designated window according to the following rules:
|
|---|
| 74 | If the character is the current erase character, left arrow, or backspace,
|
|---|
| 75 | the cursor is moved one space to the left and that screen position is erased
|
|---|
| 76 | as if \fBdelch\fR had been called.
|
|---|
| 77 | If the character value is any other \fBKEY_\fR define, the user is alerted
|
|---|
| 78 | with a \fBbeep\fR call.
|
|---|
| 79 | Otherwise the character is simply output to the screen.
|
|---|
| 80 | .PP
|
|---|
| 81 | If the window is not a pad, and it has been moved or modified since the last
|
|---|
| 82 | call to \fBwrefresh\fR, \fBwrefresh\fR will be called before another character
|
|---|
| 83 | is read.
|
|---|
| 84 | .PP
|
|---|
| 85 | If \fBkeypad\fR is \fBTRUE\fR, and a function key is pressed, the token for
|
|---|
| 86 | that function key is returned instead of the raw characters.
|
|---|
| 87 | Possible function
|
|---|
| 88 | keys are defined in \fB<curses.h>\fR as macros with values outside the range
|
|---|
| 89 | of 8-bit characters whose names begin with \fBKEY_\fR. Thus, a variable
|
|---|
| 90 | intended to hold the return value of a function key must be of short size or
|
|---|
| 91 | larger.
|
|---|
| 92 | .PP
|
|---|
| 93 | When a character that could be the beginning of a function key is received
|
|---|
| 94 | (which, on modern terminals, means an escape character),
|
|---|
| 95 | \fBcurses\fR sets a timer.
|
|---|
| 96 | If the remainder of the sequence does not come in within the designated
|
|---|
| 97 | time, the character is passed through;
|
|---|
| 98 | otherwise, the function key value is returned.
|
|---|
| 99 | For this reason, many terminals experience a delay between the time
|
|---|
| 100 | a user presses the escape key and the escape is returned to the program.
|
|---|
| 101 | .PP
|
|---|
| 102 | The \fBungetch\fR routine places \fIch\fR back onto the input queue to be
|
|---|
| 103 | returned by the next call to \fBwgetch\fR.
|
|---|
| 104 | There is just one input queue for all windows.
|
|---|
| 105 | .PP
|
|---|
| 106 | .SS Function Keys
|
|---|
| 107 | The following function keys, defined in \fB<curses.h>\fR, might be returned by
|
|---|
| 108 | \fBgetch\fR if \fBkeypad\fR has been enabled.
|
|---|
| 109 | Note that not all of these are
|
|---|
| 110 | necessarily supported on any particular terminal.
|
|---|
| 111 | .sp
|
|---|
| 112 | .TS
|
|---|
| 113 | center tab(/) ;
|
|---|
| 114 | l l
|
|---|
| 115 | l l .
|
|---|
| 116 | \fIName\fR/\fIKey\fR \fIname\fR
|
|---|
| 117 | KEY_BREAK/Break key
|
|---|
| 118 | KEY_DOWN/The four arrow keys ...
|
|---|
| 119 | KEY_UP
|
|---|
| 120 | KEY_LEFT
|
|---|
| 121 | KEY_RIGHT
|
|---|
| 122 | KEY_HOME/Home key (upward+left arrow)
|
|---|
| 123 | KEY_BACKSPACE/Backspace
|
|---|
| 124 | KEY_F0/T{
|
|---|
| 125 | Function keys; space for 64 keys is reserved.
|
|---|
| 126 | T}
|
|---|
| 127 | KEY_F(\fIn\fR)/T{
|
|---|
| 128 | For 0 \(<= \fIn\fR \(<= 63
|
|---|
| 129 | T}
|
|---|
| 130 | KEY_DL/Delete line
|
|---|
| 131 | KEY_IL/Insert line
|
|---|
| 132 | KEY_DC/Delete character
|
|---|
| 133 | KEY_IC/Insert char or enter insert mode
|
|---|
| 134 | KEY_EIC/Exit insert char mode
|
|---|
| 135 | KEY_CLEAR/Clear screen
|
|---|
| 136 | KEY_EOS/Clear to end of screen
|
|---|
| 137 | KEY_EOL/Clear to end of line
|
|---|
| 138 | KEY_SF/Scroll 1 line forward
|
|---|
| 139 | KEY_SR/Scroll 1 line backward (reverse)
|
|---|
| 140 | KEY_NPAGE/Next page
|
|---|
| 141 | KEY_PPAGE/Previous page
|
|---|
| 142 | KEY_STAB/Set tab
|
|---|
| 143 | KEY_CTAB/Clear tab
|
|---|
| 144 | KEY_CATAB/Clear all tabs
|
|---|
| 145 | KEY_ENTER/Enter or send
|
|---|
| 146 | KEY_SRESET/Soft (partial) reset
|
|---|
| 147 | KEY_RESET/Reset or hard reset
|
|---|
| 148 | KEY_PRINT/Print or copy
|
|---|
| 149 | KEY_LL/Home down or bottom (lower left)
|
|---|
| 150 | KEY_A1/Upper left of keypad
|
|---|
| 151 | KEY_A3/Upper right of keypad
|
|---|
| 152 | KEY_B2/Center of keypad
|
|---|
| 153 | KEY_C1/Lower left of keypad
|
|---|
| 154 | KEY_C3/Lower right of keypad
|
|---|
| 155 | KEY_BTAB/Back tab key
|
|---|
| 156 | KEY_BEG/Beg(inning) key
|
|---|
| 157 | KEY_CANCEL/Cancel key
|
|---|
| 158 | KEY_CLOSE/Close key
|
|---|
| 159 | KEY_COMMAND/Cmd (command) key
|
|---|
| 160 | KEY_COPY/Copy key
|
|---|
| 161 | KEY_CREATE/Create key
|
|---|
| 162 | KEY_END/End key
|
|---|
| 163 | KEY_EXIT/Exit key
|
|---|
| 164 | KEY_FIND/Find key
|
|---|
| 165 | KEY_HELP/Help key
|
|---|
| 166 | KEY_MARK/Mark key
|
|---|
| 167 | KEY_MESSAGE/Message key
|
|---|
| 168 | KEY_MOUSE/Mouse event read
|
|---|
| 169 | KEY_MOVE/Move key
|
|---|
| 170 | KEY_NEXT/Next object key
|
|---|
| 171 | KEY_OPEN/Open key
|
|---|
| 172 | KEY_OPTIONS/Options key
|
|---|
| 173 | KEY_PREVIOUS/Previous object key
|
|---|
| 174 | KEY_REDO/Redo key
|
|---|
| 175 | KEY_REFERENCE/Ref(erence) key
|
|---|
| 176 | KEY_REFRESH/Refresh key
|
|---|
| 177 | KEY_REPLACE/Replace key
|
|---|
| 178 | KEY_RESIZE/Screen resized
|
|---|
| 179 | KEY_RESTART/Restart key
|
|---|
| 180 | KEY_RESUME/Resume key
|
|---|
| 181 | KEY_SAVE/Save key
|
|---|
| 182 | KEY_SBEG/Shifted beginning key
|
|---|
| 183 | KEY_SCANCEL/Shifted cancel key
|
|---|
| 184 | KEY_SCOMMAND/Shifted command key
|
|---|
| 185 | KEY_SCOPY/Shifted copy key
|
|---|
| 186 | KEY_SCREATE/Shifted create key
|
|---|
| 187 | KEY_SDC/Shifted delete char key
|
|---|
| 188 | KEY_SDL/Shifted delete line key
|
|---|
| 189 | KEY_SELECT/Select key
|
|---|
| 190 | KEY_SEND/Shifted end key
|
|---|
| 191 | KEY_SEOL/Shifted clear line key
|
|---|
| 192 | KEY_SEXIT/Shifted exit key
|
|---|
| 193 | KEY_SFIND/Shifted find key
|
|---|
| 194 | KEY_SHELP/Shifted help key
|
|---|
| 195 | KEY_SHOME/Shifted home key
|
|---|
| 196 | KEY_SIC/Shifted input key
|
|---|
| 197 | KEY_SLEFT/Shifted left arrow key
|
|---|
| 198 | KEY_SMESSAGE/Shifted message key
|
|---|
| 199 | KEY_SMOVE/Shifted move key
|
|---|
| 200 | KEY_SNEXT/Shifted next key
|
|---|
| 201 | KEY_SOPTIONS/Shifted options key
|
|---|
| 202 | KEY_SPREVIOUS/Shifted prev key
|
|---|
| 203 | KEY_SPRINT/Shifted print key
|
|---|
| 204 | KEY_SREDO/Shifted redo key
|
|---|
| 205 | KEY_SREPLACE/Shifted replace key
|
|---|
| 206 | KEY_SRIGHT/Shifted right arrow
|
|---|
| 207 | KEY_SRSUME/Shifted resume key
|
|---|
| 208 | KEY_SSAVE/Shifted save key
|
|---|
| 209 | KEY_SSUSPEND/Shifted suspend key
|
|---|
| 210 | KEY_SUNDO/Shifted undo key
|
|---|
| 211 | KEY_SUSPEND/Suspend key
|
|---|
| 212 | KEY_UNDO/Undo key
|
|---|
| 213 | .TE
|
|---|
| 214 | .PP
|
|---|
| 215 | Keypad is arranged like this:
|
|---|
| 216 | .sp
|
|---|
| 217 | .TS
|
|---|
| 218 | center allbox tab(/) ;
|
|---|
| 219 | c c c .
|
|---|
| 220 | \fBA1\fR/\fBup\fR/\fBA3\fR
|
|---|
| 221 | \fBleft\fR/\fBB2\fR/\fBright\fR
|
|---|
| 222 | \fBC1\fR/\fBdown\fR/\fBC3\fR
|
|---|
| 223 | .TE
|
|---|
| 224 | .sp
|
|---|
| 225 | The \fBhas_key\fR routine takes a key value from the above list, and
|
|---|
| 226 | returns TRUE or FALSE according to whether
|
|---|
| 227 | the current terminal type recognizes a key with that value.
|
|---|
| 228 | Note that a few values do not correspond to a real key,
|
|---|
| 229 | e.g., \fBKEY_RESIZE\fP and \fBKEY_MOUSE\fP.
|
|---|
| 230 | See \fBresizeterm\fR(3X) for more details about \fBKEY_RESIZE\fP, and
|
|---|
| 231 | \fBcurs_mouse\fR(3X) for a discussion of \fBKEY_MOUSE\fP.
|
|---|
| 232 | .PP
|
|---|
| 233 | .SH RETURN VALUE
|
|---|
| 234 | All routines return the integer \fBERR\fR upon failure and an integer value
|
|---|
| 235 | other than \fBERR\fR (\fBOK\fR in the case of ungetch()) upon successful
|
|---|
| 236 | completion.
|
|---|
| 237 | .RS
|
|---|
| 238 | .TP 5
|
|---|
| 239 | \fBungetch\fP
|
|---|
| 240 | returns an error
|
|---|
| 241 | if there is no more room in the FIFO.
|
|---|
| 242 | .TP 5
|
|---|
| 243 | \fBwgetch\fP
|
|---|
| 244 | returns an error
|
|---|
| 245 | if the window pointer is null, or
|
|---|
| 246 | if its timeout expires without having any data.
|
|---|
| 247 | .RE
|
|---|
| 248 | .SH NOTES
|
|---|
| 249 | Use of the escape key by a programmer for a single character function is
|
|---|
| 250 | discouraged, as it will cause a delay of up to one second while the
|
|---|
| 251 | keypad code looks for a following function-key sequence.
|
|---|
| 252 | .PP
|
|---|
| 253 | Note that some keys may be the same as commonly used control
|
|---|
| 254 | keys, e.g., \fBKEY_ENTER\fP versus control/M, \fBKEY_BACKSPACE\fP versus control/H.
|
|---|
| 255 | Some curses implementations may differ according to whether they
|
|---|
| 256 | treat these control keys specially (and ignore the terminfo), or
|
|---|
| 257 | use the terminfo definitions.
|
|---|
| 258 | \fBNcurses\fR uses the terminfo definition.
|
|---|
| 259 | If it says that \fBKEY_ENTER\fP is control/M,
|
|---|
| 260 | \fBgetch\fR will return \fBKEY_ENTER\fP
|
|---|
| 261 | when you press control/M.
|
|---|
| 262 | .PP
|
|---|
| 263 | When using \fBgetch\fR, \fBwgetch\fR, \fBmvgetch\fR, or
|
|---|
| 264 | \fBmvwgetch\fR, nocbreak mode (\fBnocbreak\fR) and echo mode
|
|---|
| 265 | (\fBecho\fR) should not be used at the same time.
|
|---|
| 266 | Depending on the
|
|---|
| 267 | state of the tty driver when each character is typed, the program may
|
|---|
| 268 | produce undesirable results.
|
|---|
| 269 | .PP
|
|---|
| 270 | Note that \fBgetch\fR, \fBmvgetch\fR, and \fBmvwgetch\fR may be macros.
|
|---|
| 271 | .PP
|
|---|
| 272 | Historically, the set of keypad macros was largely defined by the extremely
|
|---|
| 273 | function-key-rich keyboard of the AT&T 7300, aka 3B1, aka Safari 4.
|
|---|
| 274 | Modern
|
|---|
| 275 | personal computers usually have only a small subset of these.
|
|---|
| 276 | IBM PC-style
|
|---|
| 277 | consoles typically support little more than \fBKEY_UP\fR, \fBKEY_DOWN\fR,
|
|---|
| 278 | \fBKEY_LEFT\fR, \fBKEY_RIGHT\fR, \fBKEY_HOME\fR, \fBKEY_END\fR,
|
|---|
| 279 | \fBKEY_NPAGE\fR, \fBKEY_PPAGE\fR, and function keys 1 through 12.
|
|---|
| 280 | The Ins key
|
|---|
| 281 | is usually mapped to \fBKEY_IC\fR.
|
|---|
| 282 | .SH PORTABILITY
|
|---|
| 283 | The *get* functions are described in the XSI Curses standard, Issue 4.
|
|---|
| 284 | They
|
|---|
| 285 | read single-byte characters only.
|
|---|
| 286 | The standard specifies that they return
|
|---|
| 287 | \fBERR\fR on failure, but specifies no error conditions.
|
|---|
| 288 | .PP
|
|---|
| 289 | The echo behavior of these functions on input of \fBKEY_\fR or backspace
|
|---|
| 290 | characters was not specified in the SVr4 documentation.
|
|---|
| 291 | This description is
|
|---|
| 292 | adopted from the XSI Curses standard.
|
|---|
| 293 | .PP
|
|---|
| 294 | The behavior of \fBgetch\fR and friends in the presence of handled signals is
|
|---|
| 295 | unspecified in the SVr4 and XSI Curses documentation.
|
|---|
| 296 | Under historical curses
|
|---|
| 297 | implementations, it varied depending on whether the operating system's
|
|---|
| 298 | implementation of handled signal receipt interrupts a \fBread\fR(2) call in
|
|---|
| 299 | progress or not, and also (in some implementations) depending on whether an
|
|---|
| 300 | input timeout or non-blocking mode has been set.
|
|---|
| 301 | .PP
|
|---|
| 302 | Programmers concerned about portability should be prepared for either of two
|
|---|
| 303 | cases: (a) signal receipt does not interrupt \fBgetch\fR; (b) signal receipt
|
|---|
| 304 | interrupts \fBgetch\fR and causes it to return ERR with \fBerrno\fR set to
|
|---|
| 305 | \fBEINTR\fR.
|
|---|
| 306 | Under the \fBncurses\fR implementation, handled signals never
|
|---|
| 307 | interrupt \fBgetch\fR.
|
|---|
| 308 | .PP
|
|---|
| 309 | The \fBhas_key\fR function is unique to \fBncurses\fR.
|
|---|
| 310 | We recommend that
|
|---|
| 311 | any code using it be conditionalized on the \fBNCURSES_VERSION\fR feature macro.
|
|---|
| 312 | .SH SEE ALSO
|
|---|
| 313 | \fBcurses\fR(3X),
|
|---|
| 314 | \fBcurs_inopts\fR(3X),
|
|---|
| 315 | \fBcurs_mouse\fR(3X),
|
|---|
| 316 | \fBcurs_move\fR(3X),
|
|---|
| 317 | \fBcurs_refresh\fR(3X),
|
|---|
| 318 | \fBresizeterm\fR(3X).
|
|---|
| 319 | .\"#
|
|---|
| 320 | .\"# The following sets edit modes for GNU EMACS
|
|---|
| 321 | .\"# Local Variables:
|
|---|
| 322 | .\"# mode:nroff
|
|---|
| 323 | .\"# fill-column:79
|
|---|
| 324 | .\"# End:
|
|---|