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