2 .\"***************************************************************************
3 .\" Copyright (c) 1998-2005,2006 Free Software Foundation, Inc. *
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: *
13 .\" The above copyright notice and this permission notice shall be included *
14 .\" in all copies or substantial portions of the Software. *
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. *
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 *
28 .\"***************************************************************************
30 .\" $Id: curs_getch.3x,v 1.30 2006/12/02 17:02:53 tom Exp $
40 \fBhas_key\fR \- get (or push back) characters from \fBcurses\fR terminal keyboard
44 \fB#include <curses.h>\fR
46 \fBint getch(void);\fR
48 \fBint wgetch(WINDOW *win);\fR
50 \fBint mvgetch(int y, int x);\fR
52 \fBint mvwgetch(WINDOW *win, int y, int x);\fR
54 \fBint ungetch(int ch);\fR
56 \fBint has_key(int ch);\fR
59 The \fBgetch\fR, \fBwgetch\fR, \fBmvgetch\fR and \fBmvwgetch\fR, routines read
60 a character from the window.
61 In no-delay mode, if no input is waiting, the value \fBERR\fR is returned.
62 In delay mode, the program waits until the system
63 passes text through to the program.
64 Depending on the setting of \fBcbreak\fR,
65 this is after one character (cbreak mode),
66 or after the first newline (nocbreak mode).
68 the program waits until a character is typed or the
69 specified timeout has been reached.
71 Unless \fBnoecho\fR has been set,
72 then the character will also be echoed into the
73 designated window according to the following rules:
74 If the character is the current erase character, left arrow, or backspace,
75 the cursor is moved one space to the left and that screen position is erased
76 as if \fBdelch\fR had been called.
77 If the character value is any other \fBKEY_\fR define, the user is alerted
78 with a \fBbeep\fR call.
79 Otherwise the character is simply output to the screen.
81 If the window is not a pad, and it has been moved or modified since the last
82 call to \fBwrefresh\fR, \fBwrefresh\fR will be called before another character
85 If \fBkeypad\fR is \fBTRUE\fR, and a function key is pressed, the token for
86 that function key is returned instead of the raw characters.
88 keys are defined in \fB<curses.h>\fR as macros with values outside the range
89 of 8-bit characters whose names begin with \fBKEY_\fR. Thus, a variable
90 intended to hold the return value of a function key must be of short size or
93 When a character that could be the beginning of a function key is received
94 (which, on modern terminals, means an escape character),
95 \fBcurses\fR sets a timer.
96 If the remainder of the sequence does not come in within the designated
97 time, the character is passed through;
98 otherwise, the function key value is returned.
99 For this reason, many terminals experience a delay between the time
100 a user presses the escape key and the escape is returned to the program.
102 The \fBungetch\fR routine places \fIch\fR back onto the input queue to be
103 returned by the next call to \fBwgetch\fR.
104 There is just one input queue for all windows.
107 The following function keys, defined in \fB<curses.h>\fR, might be returned by
108 \fBgetch\fR if \fBkeypad\fR has been enabled.
109 Note that not all of these are
110 necessarily supported on any particular terminal.
116 \fIName\fR/\fIKey\fR \fIname\fR
118 KEY_DOWN/The four arrow keys ...
122 KEY_HOME/Home key (upward+left arrow)
123 KEY_BACKSPACE/Backspace
125 Function keys; space for 64 keys is reserved.
128 For 0 \(<= \fIn\fR \(<= 63
132 KEY_DC/Delete character
133 KEY_IC/Insert char or enter insert mode
134 KEY_EIC/Exit insert char mode
135 KEY_CLEAR/Clear screen
136 KEY_EOS/Clear to end of screen
137 KEY_EOL/Clear to end of line
138 KEY_SF/Scroll 1 line forward
139 KEY_SR/Scroll 1 line backward (reverse)
141 KEY_PPAGE/Previous page
144 KEY_CATAB/Clear all tabs
145 KEY_ENTER/Enter or send
146 KEY_SRESET/Soft (partial) reset
147 KEY_RESET/Reset or hard reset
148 KEY_PRINT/Print or copy
149 KEY_LL/Home down or bottom (lower left)
150 KEY_A1/Upper left of keypad
151 KEY_A3/Upper right of keypad
152 KEY_B2/Center of keypad
153 KEY_C1/Lower left of keypad
154 KEY_C3/Lower right of keypad
155 KEY_BTAB/Back tab key
156 KEY_BEG/Beg(inning) key
157 KEY_CANCEL/Cancel key
159 KEY_COMMAND/Cmd (command) key
161 KEY_CREATE/Create key
167 KEY_MESSAGE/Message key
168 KEY_MOUSE/Mouse event read
170 KEY_NEXT/Next object key
172 KEY_OPTIONS/Options key
173 KEY_PREVIOUS/Previous object key
175 KEY_REFERENCE/Ref(erence) key
176 KEY_REFRESH/Refresh key
177 KEY_REPLACE/Replace key
178 KEY_RESIZE/Screen resized
179 KEY_RESTART/Restart key
180 KEY_RESUME/Resume key
182 KEY_SBEG/Shifted beginning key
183 KEY_SCANCEL/Shifted cancel key
184 KEY_SCOMMAND/Shifted command key
185 KEY_SCOPY/Shifted copy key
186 KEY_SCREATE/Shifted create key
187 KEY_SDC/Shifted delete char key
188 KEY_SDL/Shifted delete line key
189 KEY_SELECT/Select key
190 KEY_SEND/Shifted end key
191 KEY_SEOL/Shifted clear line key
192 KEY_SEXIT/Shifted exit key
193 KEY_SFIND/Shifted find key
194 KEY_SHELP/Shifted help key
195 KEY_SHOME/Shifted home key
196 KEY_SIC/Shifted input key
197 KEY_SLEFT/Shifted left arrow key
198 KEY_SMESSAGE/Shifted message key
199 KEY_SMOVE/Shifted move key
200 KEY_SNEXT/Shifted next key
201 KEY_SOPTIONS/Shifted options key
202 KEY_SPREVIOUS/Shifted prev key
203 KEY_SPRINT/Shifted print key
204 KEY_SREDO/Shifted redo key
205 KEY_SREPLACE/Shifted replace key
206 KEY_SRIGHT/Shifted right arrow
207 KEY_SRSUME/Shifted resume key
208 KEY_SSAVE/Shifted save key
209 KEY_SSUSPEND/Shifted suspend key
210 KEY_SUNDO/Shifted undo key
211 KEY_SUSPEND/Suspend key
215 Keypad is arranged like this:
218 center allbox tab(/) ;
220 \fBA1\fR/\fBup\fR/\fBA3\fR
221 \fBleft\fR/\fBB2\fR/\fBright\fR
222 \fBC1\fR/\fBdown\fR/\fBC3\fR
225 The \fBhas_key\fR routine takes a key value from the above list, and
226 returns TRUE or FALSE according to whether
227 the current terminal type recognizes a key with that value.
228 Note that a few values do not correspond to a real key,
229 e.g., \fBKEY_RESIZE\fP and \fBKEY_MOUSE\fP.
230 See \fBresizeterm\fR(3X) for more details about \fBKEY_RESIZE\fP, and
231 \fBcurs_mouse\fR(3X) for a discussion of \fBKEY_MOUSE\fP.
234 All routines return the integer \fBERR\fR upon failure and an integer value
235 other than \fBERR\fR (\fBOK\fR in the case of ungetch()) upon successful
241 if there is no more room in the FIFO.
245 if the window pointer is null, or
246 if its timeout expires without having any data.
249 Use of the escape key by a programmer for a single character function is
250 discouraged, as it will cause a delay of up to one second while the
251 keypad code looks for a following function-key sequence.
253 Note that some keys may be the same as commonly used control
254 keys, e.g., \fBKEY_ENTER\fP versus control/M, \fBKEY_BACKSPACE\fP versus control/H.
255 Some curses implementations may differ according to whether they
256 treat these control keys specially (and ignore the terminfo), or
257 use the terminfo definitions.
258 \fBNcurses\fR uses the terminfo definition.
259 If it says that \fBKEY_ENTER\fP is control/M,
260 \fBgetch\fR will return \fBKEY_ENTER\fP
261 when you press control/M.
263 When using \fBgetch\fR, \fBwgetch\fR, \fBmvgetch\fR, or
264 \fBmvwgetch\fR, nocbreak mode (\fBnocbreak\fR) and echo mode
265 (\fBecho\fR) should not be used at the same time.
267 state of the tty driver when each character is typed, the program may
268 produce undesirable results.
270 Note that \fBgetch\fR, \fBmvgetch\fR, and \fBmvwgetch\fR may be macros.
272 Historically, the set of keypad macros was largely defined by the extremely
273 function-key-rich keyboard of the AT&T 7300, aka 3B1, aka Safari 4.
275 personal computers usually have only a small subset of these.
277 consoles typically support little more than \fBKEY_UP\fR, \fBKEY_DOWN\fR,
278 \fBKEY_LEFT\fR, \fBKEY_RIGHT\fR, \fBKEY_HOME\fR, \fBKEY_END\fR,
279 \fBKEY_NPAGE\fR, \fBKEY_PPAGE\fR, and function keys 1 through 12.
281 is usually mapped to \fBKEY_IC\fR.
283 The *get* functions are described in the XSI Curses standard, Issue 4.
285 read single-byte characters only.
286 The standard specifies that they return
287 \fBERR\fR on failure, but specifies no error conditions.
289 The echo behavior of these functions on input of \fBKEY_\fR or backspace
290 characters was not specified in the SVr4 documentation.
292 adopted from the XSI Curses standard.
294 The behavior of \fBgetch\fR and friends in the presence of handled signals is
295 unspecified in the SVr4 and XSI Curses documentation.
296 Under historical curses
297 implementations, it varied depending on whether the operating system's
298 implementation of handled signal receipt interrupts a \fBread\fR(2) call in
299 progress or not, and also (in some implementations) depending on whether an
300 input timeout or non-blocking mode has been set.
302 Programmers concerned about portability should be prepared for either of two
303 cases: (a) signal receipt does not interrupt \fBgetch\fR; (b) signal receipt
304 interrupts \fBgetch\fR and causes it to return ERR with \fBerrno\fR set to
306 Under the \fBncurses\fR implementation, handled signals never
307 interrupt \fBgetch\fR.
309 The \fBhas_key\fR function is unique to \fBncurses\fR.
311 any code using it be conditionalized on the \fBNCURSES_VERSION\fR feature macro.
314 \fBcurs_inopts\fR(3X),
315 \fBcurs_mouse\fR(3X),
317 \fBcurs_refresh\fR(3X),
318 \fBresizeterm\fR(3X).
320 Comparable functions in the wide-character (ncursesw) library are
322 \fBcurs_get_wch\fR(3X).
324 .\"# The following sets edit modes for GNU EMACS
325 .\"# Local Variables: