2 .\"***************************************************************************
3 .\" Copyright 2018-2023,2024 Thomas E. Dickey *
4 .\" Copyright 1998-2016,2017 Free Software Foundation, Inc. *
6 .\" Permission is hereby granted, free of charge, to any person obtaining a *
7 .\" copy of this software and associated documentation files (the *
8 .\" "Software"), to deal in the Software without restriction, including *
9 .\" without limitation the rights to use, copy, modify, merge, publish, *
10 .\" distribute, distribute with modifications, sublicense, and/or sell *
11 .\" copies of the Software, and to permit persons to whom the Software is *
12 .\" furnished to do so, subject to the following conditions: *
14 .\" The above copyright notice and this permission notice shall be included *
15 .\" in all copies or substantial portions of the Software. *
17 .\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
18 .\" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
19 .\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
20 .\" IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
21 .\" DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
22 .\" OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
23 .\" THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
25 .\" Except as contained in this notice, the name(s) of the above copyright *
26 .\" holders shall not be used in advertising or otherwise to promote the *
27 .\" sale, use or other dealings in this Software without prior written *
29 .\"***************************************************************************
31 .\" $Id: curs_getch.3x,v 1.97 2024/06/08 20:26:46 tom Exp $
32 .TH curs_getch 3X 2024-06-08 "ncurses @NCURSES_MAJOR@.@NCURSES_MINOR@" "Library calls"
60 get (or push back) characters from \fIcurses\fR terminal keyboard
63 .B #include <curses.h>
66 .B int wgetch(WINDOW *\fIwin\fP);
67 .B int mvgetch(int \fIy\fP, int \fIx\fP);
68 .B int mvwgetch(WINDOW *\fIwin\fP, int \fIy\fP, int \fIx\fP);
70 .B int ungetch(int \fIc\fP);
72 .\" XXX: Move has_key into its own page like define_key and key_defined?
74 .B int has_key(int \fIc\fP);
77 .SS "Reading Characters"
79 gathers a key event from the terminal keyboard associated with a
83 \fB\%ncurses\fP(3X) describes the variants of this function.
85 When input is pending,
87 returns an integer identifying the key event;
88 for alphanumeric and punctuation keys,
89 this value corresponds to the character encoding used by the terminal.
90 Use of the control key as a modifier,
91 by holding it down while pressing and releasing another key,
92 often results in a distinct code.
93 The behavior of other keys depends on whether
96 see subsection \*(``Keypad Mode\*('' below.
98 If no input is pending,
99 then if the no-delay flag is set in the window
100 (see \fB\%nodelay\fP(3X)),
105 waits until the terminal has input.
106 If \fB\%cbreak\fP(3X)
108 this happens after one character is read.
109 If \fB\%nocbreak\fP(3X) or \fB\%noraw\fP(3X)
111 it occurs when the next newline is read.
112 (Because the terminal's normal or \*(``cooked\*('' mode
116 calls may then be necessary to empty the input queue.)
117 If \fB\%halfdelay\fP(3X)
120 waits until input is available or the specified delay elapses.
122 If \fB\%echo\fP(3X) has been called,
123 and the window is not a pad,
125 writes the returned character
128 (at the cursor position)
129 per the following rules.
133 matches the terminal's erase character
134 (see \fB\%erasechar\fP(3X)),
135 the cursor moves leftward one position
136 and the new position is erased
137 as if \fB\%wmove\fP(3X) and then \fB\%wdelch\fP(3X) were called.
138 When the window's keypad mode is enabled
143 are handled the same way.
149 as with \fB\%wechochar\fP(3X).
153 has been moved or modified since the last call to
154 \fB\%wrefresh\fP(3X),
162 is a carriage return and \fBnl\fP(3X) has been called,
164 returns the character code for line feed instead.
168 key strokes not from the alphabetic section of the keyboard
169 (those corresponding to the ECMA-6 character set\(emsee
170 \fI\%ascii\fP(7)\(emoptionally modified by either the control or shift
177 the term \*(``function key\*('' includes but is not limited to keycaps
178 engraved with \*(``F1\*('',
181 If the window is in keypad mode,
182 these produce a numeric code corresponding to the
184 symbols listed in subsection \*(``Predefined Key Codes\*('' below;
186 they transmit a sequence of codes typically starting with the escape
188 and which must be collected with multiple
194 header file declares many
195 .I "predefined function keys"
196 whose names begin with
198 these object-like macros have values outside the range of eight-bit
203 .I "user-defined function keys"
204 are configured with \fB\%define_key\fP(3X);
206 but are also expected to have values outside the range of eight-bit
209 A variable intended to hold a function key code must thus be of type
213 Most terminals one encounters follow the ECMA-48 standard insofar as
214 their function keys produce character sequences prefixed with the
215 escape character ESC.
216 This fact implies that
218 cannot distinguish a user's press of the escape key
219 (assuming it sends ESC)
220 from the beginning of a function key's character sequence without
223 further input arrives.
226 reads such an ambiguous character,
228 If the remainder of the sequence does not arrive within the designated
231 returns the prefix character;
233 it returns the function key code corresponding to the unique sequence
234 defined by the terminal.
238 application may experience a delay after the escape key is pressed
241 disambiguates the input;
242 see section \*(``EXTENSIONS\*('' below.
243 If the window is in \*(``no time-out\*('' mode,
244 the timer does not expire;
248 See \fB\%notimeout\fP(3X).
249 Because function key sequences usually begin with ESC,
250 the terminal may appear to hang in no time-out mode after the user
251 presses the escape key.
253 further typing \*(``awakens\*(''
255 .SS "Ungetting Characters"
259 into the input queue to be returned by the next call to
261 A single input queue serves all windows associated with the terminal.
262 .SS "Predefined Key Codes"
265 defines the following function key codes.
267 Except for the special case of
269 a window's keypad mode must be enabled for
271 to read these codes from it.
273 Not all of these are necessarily supported on any particular terminal.
275 The naming convention may seem obscure,
276 with some apparent misspellings
277 (such as \*(``RSUME\*('' for \*(``resume\*('');
278 the names correspond to the
280 capability names for the keys,
281 and were standardized before the IBM PC/AT keyboard layout achieved a
282 dominant position in industry.
285 .\" XXX: Move this list into ncurses(3X), rather than duplicating it in
286 .\" get_wch(3X) or having that page cross reference this one?
297 KEY_HOME Home key (upward+left arrow)
298 KEY_BACKSPACE Backspace
300 Function keys; space for 64 keys is reserved
303 Function key \fIn\fP where 0 \(<= \fIn\fP \(<= 63
307 KEY_DC Delete character
308 KEY_IC Insert character/Enter insert mode
309 KEY_EIC Exit insert character mode
310 KEY_CLEAR Clear screen
311 KEY_EOS Clear to end of screen
312 KEY_EOL Clear to end of line
313 KEY_SF Scroll one line forward
314 KEY_SR Scroll one line backward (reverse)
315 KEY_NPAGE Next page/Page up
316 KEY_PPAGE Previous page/Page down
319 KEY_CATAB Clear all tabs
321 KEY_SRESET Soft (partial) reset
322 KEY_RESET (Hard) reset
324 KEY_LL Home down/Bottom (lower left)
325 KEY_A1 Upper left of keypad
326 KEY_A3 Upper right of keypad
327 KEY_B2 Center of keypad
328 KEY_C1 Lower left of keypad
329 KEY_C3 Lower right of keypad
330 KEY_BTAB Back tab key
331 KEY_BEG Beg(inning) key
332 KEY_CANCEL Cancel key
334 KEY_COMMAND Cmd (command) key
336 KEY_CREATE Create key
342 KEY_MESSAGE Message key
343 KEY_MOUSE Mouse event occurred
345 KEY_NEXT Next object key
347 KEY_OPTIONS Options key
348 KEY_PREVIOUS Previous object key
350 KEY_REFERENCE Ref(erence) key
351 KEY_REFRESH Refresh key
352 KEY_REPLACE Replace key
353 KEY_RESIZE Screen resized
354 KEY_RESTART Restart key
355 KEY_RESUME Resume key
357 KEY_SELECT Select key
358 KEY_SUSPEND Suspend key
361 KEY_SBEG Shifted beginning key
362 KEY_SCANCEL Shifted cancel key
363 KEY_SCOMMAND Shifted command key
364 KEY_SCOPY Shifted copy key
365 KEY_SCREATE Shifted create key
366 KEY_SDC Shifted delete character key
367 KEY_SDL Shifted delete line key
368 KEY_SEND Shifted end key
369 KEY_SEOL Shifted clear line key
370 KEY_SEXIT Shifted exit key
371 KEY_SFIND Shifted find key
372 KEY_SHELP Shifted help key
373 KEY_SHOME Shifted home key
374 KEY_SIC Shifted insert key
375 KEY_SLEFT Shifted left arrow key
376 KEY_SMESSAGE Shifted message key
377 KEY_SMOVE Shifted move key
378 KEY_SNEXT Shifted next object key
379 KEY_SOPTIONS Shifted options key
380 KEY_SPREVIOUS Shifted previous object key
381 KEY_SPRINT Shifted print key
382 KEY_SREDO Shifted redo key
383 KEY_SREPLACE Shifted replace key
384 KEY_SRIGHT Shifted right arrow key
385 KEY_SRSUME Shifted resume key
386 KEY_SSAVE Shifted save key
387 KEY_SSUSPEND Shifted suspend key
388 KEY_SUNDO Shifted undo key
392 Many keyboards feature a nine-key directional pad.
404 Two of the symbols in the list above do
406 correspond to a physical key.
411 even if the window's keypad mode is disabled,
419 see \fB\%initscr\fP(3X) and \fB\%resizeterm\fP(3X).
424 to indicate that a mouse event is pending collection;
425 see \fB\%curs_mouse\fP(3X).
426 Receipt of this code requires a window's keypad mode to be enabled,
427 because to interpret mouse input
428 (as with with \fI\%xterm\fP(1)'s mouse protocol),
430 must read an escape sequence,
431 as with a function key.
432 .SS "Testing Key Codes"
436 returns a Boolean value indicating whether the terminal type recognizes
437 its parameter as a key code value.
439 \fB\%define_key\fP(3X) and \fB\%key_defined\fP(3X).
443 these functions return
451 pointer argument fail if the pointer is
454 Functions prefixed with \*(``mv\*('' first perform cursor movement and
458 is outside the window boundaries.
463 its timeout expires without any data arriving,
466 execution was interrupted by a signal,
473 fails if there is no more room in the input queue.
485 may be implemented as macros.
488 discourages assignment of the ESC key to a discrete function by the
489 programmer because the library requires a delay while it awaits the
490 potential remainder of a terminal escape sequence.
492 Some key strokes are indistinguishable from control characters;
497 .\" as with att630 or pccon+keys
502 .\" as with att505 or vt52-basic
505 .\" as with pccon+keys or vt320
508 entry for the terminal type to determine whether this is the case;
509 see \fB\%infocmp\fP(1).
518 others treat such control characters specially.
521 distinguishes the Enter keys in the alphabetic and numeric keypad
522 sections of a keyboard because (most) terminals do.
524 refers to the key on the numeric keypad and,
525 like other function keys,
526 is reliably recognized only if the window's keypad mode is enabled.
532 capability describes the character (sequence) sent by the Enter key of
537 \*(``Enter or send\*('' is X/Open Curses's description of this key.
540 treats the Enter or Return key in the
542 section of the keyboard differently.
544 It usually produces a control code for carriage return
549 Depending on the terminal mode
554 and whether \fB\%nl\fP(3X) or \fB\%nonl\fP(3X) has been called,
556 may return either a carriage return or line feed upon an Enter or Return
561 with \fB\%echo\fP(3X) and neither \fB\%cbreak\fP(3X) nor \fB\%raw\fP(3X)
565 the list of key code macros above was influenced by the keyboard of the
567 (also known variously as the \*(``3B1\*('', \*(``Safari 4\*('', and
569 a 1985 machine rich in function keys.
570 Today's computer keyboards are based on that of the IBM PC/AT
571 and tend to have fewer.
574 application can expect such a keyboard to transmit key codes
597 when a window's \*(``no time-out\*('' mode is
602 variable configures the duration of the timer used to disambiguate a
603 function key character sequence from a series of key strokes beginning
604 with ESC typed by the user;
606 \fB\%curs_variables\fP(3X).
611 and is not found in SVr4
615 or any other previous
619 Applications employing
621 extensions should condition their use on the visibility of the
625 Except as noted in section \*(``EXTENSIONS\*('' above,
627 Issue 4 describes these functions.
628 It specifies no error conditions for them.
631 reads only single-byte characters.
633 The echo behavior of these functions on input of
635 or backspace characters is not documented in SVr4
640 in the presence of signal handlers is not documented in SVr4
642 and is unspecified by X/Open Curses.
646 it varied depending on whether the operating system's dispatch of a
647 signal to a handler interrupted a \fIread\fP(2) call in progress,
649 (in some implementations)
650 whether an input timeout or non-blocking mode had been set.
653 application prepares for two cases:
654 (a) signal receipt does not interrupt
657 (b) signal receipt interrupts
659 and causes it to return
667 is mentioned in X/Open Curses,
668 along with a few related
671 but no higher-level functions use the feature.
672 The implementation in
679 are extensions first implemented for
683 .\" https://web.archive.org/web/20220117232009/https://pdcurses.org/docs/MANUAL.html
687 .\" https://web.archive.org/web/20200923185647/https://man.netbsd.org/curses_input.3
688 had added them along with
691 ECMA-6 \*(``7-bit coded Character Set\*(''
692 \%<https://\*:ecma\-international\*:.org/\
693 \*:publications\-and\-standards/\*:standards/\*:ecma\-6/>
695 ECMA-48 \*(``Control Functions for Coded Character Sets\*(''
696 \%<https://\*:ecma\-international\*:.org/\
697 \*:publications\-and\-standards/\*:standards/\*:ecma\-48/>
699 \fB\%curs_get_wch\fP(3X) describes comparable functions of the
701 library in its wide-character configuration
705 \fB\%curs_addch\fP(3X),
706 \fB\%curs_inopts\fP(3X),
707 \fB\%curs_mouse\fP(3X),
708 \fB\%curs_move\fP(3X),
709 \fB\%curs_outopts\fP(3X),
710 \fB\%curs_refresh\fP(3X),
711 \fB\%curs_variables\fP(3X),
712 \fB\%resizeterm\fP(3X),