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