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