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.83 2024/03/23 20:38:57 tom Exp $
32 .TH curs_getch 3X 2024-03-23 "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 \fIch\fP);
72 .\" XXX: Move has_key into its own page like define_key and key_defined?
74 .B int has_key(int \fIch\fP);
77 .SS "Reading Characters"
79 gathers a key stroke 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 stroke;
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 often results in a distinct code.
91 The behavior of other keys depends on whether
94 see subsection \*(``Keypad Mode\*('' below.
96 If no input is pending,
97 then if the no-delay flag is set in the window
98 (see \fB\%nodelay\fP(3X)),
103 waits until the terminal has input.
104 If \fB\%cbreak\fP(3X)
106 this happens after one character is read.
107 If \fB\%nocbreak\fP(3X)
109 it occurs when the next newline is read.
110 If \fB\%halfdelay\fP(3X)
113 waits until a character is typed or the specified delay elapses.
115 If \fB\%echo\fP(3X) has been called,
116 and the window is not a pad,
118 writes the returned character
121 (at the cursor position)
122 per the following rules.
126 matches the terminal's erase character,
127 the cursor moves leftward one position
128 and the new position is erased
129 as if \fB\%wmove\fP(3X) and then \fB\%wdelch\fP(3X) were called.
130 When the window's keypad mode is enabled
135 are handled the same way.
141 as with \fB\%wechochar\fP(3X).
143 If the window has been moved or modified since the last call to
144 \fB\%wrefresh\fP(3X),
151 is a carriage return and \fBnl\fP(3X) has been called,
153 returns the character code for newline
159 key strokes not from the alphabetic section of the keyboard
160 (those corresponding to the ECMA-6 character set\(emsee
161 \fIascii\fP(7)\(emoptionally modified by either the control or shift
168 the term \*(``function key\*('' includes but is not limited to keycaps
169 engraved with \*(``F1\*('',
172 If the window is in keypad mode,
173 these produce a numeric code corresponding to the
175 symbols listed in subsection \*(``Predefined Key Codes\*('' below;
177 they transmit a sequence of codes typically starting with the escape
179 and which must be collected with multiple
185 header file declares many
186 .I "predefined function keys"
187 whose names begin with
189 these object-like macros have values outside the range of eight-bit
194 .I "user-defined function keys"
195 are configured with \fBdefine_key\fP(3X);
197 but are also expected to have values outside the range of eight-bit
200 A variable intended to hold a function key code must thus be of type
204 Most terminals one encounters follow the ECMA-48 standard insofar as
205 their function keys produce character sequences prefixed with the
206 escape character ESC.
207 This fact implies that
209 cannot know whether the terminal has sent an ESC key stroke or the
210 beginning of a function key's character sequence without waiting to see
213 further input arrives.
216 reads such an ambiguous character,
218 If the remainder of the sequence does not arrive within the designated
221 returns the prefix character;
223 it returns the function key code corresponding to the unique sequence
224 defined by the terminal.
228 application may experience a delay after pressing ESC while
230 disambiguates the input.
231 See section \*(``EXTENSIONS\*('' below.
232 If the window is in \*(``no time-out\*('' mode,
233 the timer does not expire;
237 See \fB\%notimeout\fP(3X).
238 Because function key sequences usually begin with an escape character,
239 the terminal may appear to hang in no time-out mode after the user has
242 further typing \*(``awakens\*(''
244 .SS "Ungetting Characters"
248 into the input queue to be returned by the next call to
250 A single input queue serves all windows.
251 .SS "Predefined Key Codes"
254 defines the following function key codes.
256 Except for the special case of
258 a window's keypad mode must be enabled for
260 to read these codes from it.
262 Not all of these are necessarily supported on any particular terminal.
264 The naming convention may seem obscure,
265 with some apparent misspellings
266 (such as \*(``RSUME\*('' for \*(``resume\*('');
267 The names correspond to the
269 capability names for the keys,
270 and were standardized before the IBM PC/AT keyboard layout achieved a
271 dominant position in industry.
274 .\" XXX: Move this list into ncurses(3X), rather than duplicating it in
275 .\" get_wch(3X) or having that page cross reference this one?
286 KEY_HOME Home key (upward+left arrow)
287 KEY_BACKSPACE Backspace
289 Function keys; space for 64 keys is reserved
292 Function key \fIn\fP where 0 \(<= \fIn\fP \(<= 63
296 KEY_DC Delete character
297 KEY_IC Insert character/Enter insert mode
298 KEY_EIC Exit insert character mode
299 KEY_CLEAR Clear screen
300 KEY_EOS Clear to end of screen
301 KEY_EOL Clear to end of line
302 KEY_SF Scroll one line forward
303 KEY_SR Scroll one line backward (reverse)
304 KEY_NPAGE Next page/Page up
305 KEY_PPAGE Previous page/Page down
308 KEY_CATAB Clear all tabs
310 KEY_SRESET Soft (partial) reset
311 KEY_RESET (Hard) reset
313 KEY_LL Home down/Bottom (lower left)
314 KEY_A1 Upper left of keypad
315 KEY_A3 Upper right of keypad
316 KEY_B2 Center of keypad
317 KEY_C1 Lower left of keypad
318 KEY_C3 Lower right of keypad
319 KEY_BTAB Back tab key
320 KEY_BEG Beg(inning) key
321 KEY_CANCEL Cancel key
323 KEY_COMMAND Cmd (command) key
325 KEY_CREATE Create key
331 KEY_MESSAGE Message key
332 KEY_MOUSE Mouse event occurred
334 KEY_NEXT Next object key
336 KEY_OPTIONS Options key
337 KEY_PREVIOUS Previous object key
339 KEY_REFERENCE Ref(erence) key
340 KEY_REFRESH Refresh key
341 KEY_REPLACE Replace key
342 KEY_RESIZE Screen resized
343 KEY_RESTART Restart key
344 KEY_RESUME Resume key
346 KEY_SELECT Select key
347 KEY_SUSPEND Suspend key
350 KEY_SBEG Shifted beginning key
351 KEY_SCANCEL Shifted cancel key
352 KEY_SCOMMAND Shifted command key
353 KEY_SCOPY Shifted copy key
354 KEY_SCREATE Shifted create key
355 KEY_SDC Shifted delete character key
356 KEY_SDL Shifted delete line key
357 KEY_SEND Shifted end key
358 KEY_SEOL Shifted clear line key
359 KEY_SEXIT Shifted exit key
360 KEY_SFIND Shifted find key
361 KEY_SHELP Shifted help key
362 KEY_SHOME Shifted home key
363 KEY_SIC Shifted insert key
364 KEY_SLEFT Shifted left arrow key
365 KEY_SMESSAGE Shifted message key
366 KEY_SMOVE Shifted move key
367 KEY_SNEXT Shifted next object key
368 KEY_SOPTIONS Shifted options key
369 KEY_SPREVIOUS Shifted previous object key
370 KEY_SPRINT Shifted print key
371 KEY_SREDO Shifted redo key
372 KEY_SREPLACE Shifted replace key
373 KEY_SRIGHT Shifted right arrow key
374 KEY_SRSUME Shifted resume key
375 KEY_SSAVE Shifted save key
376 KEY_SSUSPEND Shifted suspend key
377 KEY_SUNDO Shifted undo key
381 The keypad is arranged as follows.
393 Two of these symbols do
395 correspond to a real key.
400 (even if the window's keypad mode is disabled)
406 see \fBinitscr\fP(3X) and \fBresizeterm\fP(3X).
411 to indicate that a mouse event is pending collection;
412 see \fBcurs_mouse\fP(3X).
413 Receipt of this code requires a window's keypad mode to be enabled,
414 because to interpret mouse input
415 (as with with \fIxterm\fP(1)'s mouse prototocol),
417 must read an escape sequence,
418 as with a function key.
419 .SS "Testing Key Codes"
423 takes a key code value from the above list,
424 and returns a Boolean value indicating the terminal's recognition of it.
426 \fBdefine_key\fP(3X) and \fBkey_defined\fP(3X).
439 its timeout expires without any data arriving,
442 execution was interrupted by a signal,
448 Functions with a \*(``mv\*('' prefix first perform cursor movement using
449 \fB\%wmove\fP(3X) and fail if the position is outside the window,
451 (for \*(``mvw\*('' functions)
454 parameter is a null pointer.
461 if there is no more room in the input queue.
470 discourages assignment of the ESC key to a discrete function by the
471 programmer because the library requires a delay while it awaits the
472 potential remainder of a terminal escape sequence.
474 Some key strokes are indistinguishable from control characters;
479 .\" as with att630 or pccon+keys
484 .\" as with att505 or vt52-basic
487 .\" as with pccon+keys or vt320
488 Consult the terminal's
490 entry to determine whether this is the case;
491 see \fB\%infocmp\fP(1).
500 others treat such control characters specially.
503 distinguishes the Enter keys in the alphabetic and numeric keypad
504 sections of a keyboard because (most) terminals do.
506 refers to the key on the (numeric) keypad and,
507 like other function keys,
508 is reliably recognized only if the window's keypad mode is enabled.
514 capability describes the character (sequence) sent by the terminal's
517 \*(``Enter or send\*('' is X/Open Curses's description of this key.
520 treats the Enter or Return key in the
522 section of the keyboard differently.
524 It usually produces a control code for carriage return
529 Depending on the terminal mode
534 and whether \fB\%nl\fP(3X) or \fB\%nonl\fP(3X) has been called,
536 may return either a carriage return or line feed upon an Enter or Return
541 with \fB\%echo\fP(3X) and neither \fB\%cbreak\fP(3X) nor \fB\%raw\fP(3X)
545 the list of key code macros above was influenced by the
546 function-key-rich keyboard of the AT&T 7300
547 (also known variously as the \*(``3B1\*('', \*(``Safari 4\*('', and
550 Today's computer keyboards are based on the IBM PC/AT keyboard and tend
554 application can expect such a keyboard to transmit key codes
579 may be implemented as macros.
583 when a window's \*(``no time-out\*('' mode is
588 variable configures the duration of the timer used to disambiguate a
589 function key character sequence from a series of key strokes beginning
590 with ESC typed by the user;
592 \fB\%curs_variables\fP(3X).
594 \fB\%has_key\fP was designed for \fB\%ncurses\fP(3X),
595 and is not found in SVr4
599 or any other previous curses implementation.
601 Applications employing
603 extensions should condition their use on the visibility of the
607 X/Open Curses, Issue 4, describes
614 It specifies no error conditions for them.
617 reads only single-byte characters.
619 The echo behavior of these functions on input of
621 or backspace characters was not specified in the SVr4 documentation.
622 This description is adapted from X/Open Curses.
626 in the presence of signal handlers is unspecified in the SVr4
627 documentation and X/Open Curses.
631 it varied depending on whether the operating system's dispatch of a
632 signal to a handler interrupts a \fIread\fP(2) call in progress or not,
634 (in some implementations)
635 whether an input timeout or non-blocking mode has been set.
636 Programmers concerned about portability should be prepared for either of
638 (a) signal receipt does not interrupt
641 (b) signal receipt interrupts
643 and causes it to return
651 is mentioned in X/Open Curses,
652 along with a few related
655 but no higher-level functions use the feature.
656 The implementation in
663 are extensions first implemented for
667 .\" https://web.archive.org/web/20220117232009/https://pdcurses.org/docs/MANUAL.html
671 .\" https://web.archive.org/web/20200923185647/https://man.netbsd.org/curses_input.3
672 had added them along with
676 \fB\%curs_addch\fP(3X),
677 \fB\%curs_inopts\fP(3X),
678 \fB\%curs_mouse\fP(3X),
679 \fB\%curs_move\fP(3X),
680 \fB\%curs_outopts\fP(3X),
681 \fB\%curs_refresh\fP(3X),
682 \fB\%curs_variables\fP(3X),
683 \fB\%resizeterm\fP(3X),
686 \fB\%curs_get_wch\fP(3X) describes comparable functions of the
688 library in its wide-character configuration
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/>