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