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