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