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