| 1 |
'\" t |
| 2 |
.\"*************************************************************************** |
| 3 |
.\" Copyright 2018-2024,2025 Thomas E. Dickey * |
| 4 |
.\" Copyright 1998-2016,2017 Free Software Foundation, Inc. * |
| 5 |
.\" * |
| 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: * |
| 13 |
.\" * |
| 14 |
.\" The above copyright notice and this permission notice shall be included * |
| 15 |
.\" in all copies or substantial portions of the Software. * |
| 16 |
.\" * |
| 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. * |
| 24 |
.\" * |
| 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 * |
| 28 |
.\" authorization. * |
| 29 |
.\"*************************************************************************** |
| 30 |
.\" |
| 31 |
.\" $Id: curs_getch.3x,v 1.134 2025/11/12 01:06:36 tom Exp $ |
| 32 |
.TH getch 3NCURSES 2025-11-11 "ncurses 6.6" "Library calls" |
| 33 |
.ie \n(.g \{\ |
| 34 |
.ds `` \(lq |
| 35 |
.ds '' \(rq |
| 36 |
.ds ^ \(ha |
| 37 |
.\} |
| 38 |
.el \{\ |
| 39 |
.ie t .ds `` `` |
| 40 |
.el .ds `` "" |
| 41 |
.ie t .ds '' '' |
| 42 |
.el .ds '' "" |
| 43 |
.ds ^ ^ |
| 44 |
.\} |
| 45 |
. |
| 46 |
.ie \n(.g .ds : \: |
| 47 |
.el .ds : \" empty |
| 48 |
. |
| 49 |
.de bP |
| 50 |
.ie n .IP \(bu 4 |
| 51 |
.el .IP \(bu 2 |
| 52 |
.. |
| 53 |
.SH NAME |
| 54 |
\fB\%getch\fP, |
| 55 |
\fB\%wgetch\fP, |
| 56 |
\fB\%mvgetch\fP, |
| 57 |
\fB\%mvwgetch\fP, |
| 58 |
\fB\%ungetch\fP, |
| 59 |
\fB\%has_key\fP \- |
| 60 |
get (or push back) characters from \fIcurses\fR terminal keyboard buffer |
| 61 |
.SH SYNOPSIS |
| 62 |
.nf |
| 63 |
.B #include <curses.h> |
| 64 |
.PP |
| 65 |
.B int getch(void); |
| 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); |
| 69 |
.PP |
| 70 |
.B int ungetch(int \fIc\fP); |
| 71 |
.PP |
| 72 |
.\" XXX: Move has_key into its own page like define_key and key_defined? |
| 73 |
\fI/* extension */\fP |
| 74 |
.B int has_key(int \fIc\fP); |
| 75 |
.fi |
| 76 |
.SH DESCRIPTION |
| 77 |
.SS "Reading Characters" |
| 78 |
.B \%wgetch |
| 79 |
gathers a key event from the terminal keyboard associated with a |
| 80 |
.I curses |
| 81 |
window |
| 82 |
.IR win "." |
| 83 |
\fB\%ncurses\fP(3NCURSES) describes the variants of this function. |
| 84 |
.PP |
| 85 |
When input is pending, |
| 86 |
.B \%wgetch |
| 87 |
returns an integer identifying the key event; |
| 88 |
for alphanumeric and punctuation keys, |
| 89 |
the space bar, |
| 90 |
and (usually) the Backspace, |
| 91 |
Tab, |
| 92 |
Return, |
| 93 |
and Escape keys, |
| 94 |
this value corresponds to the character encoding used by the terminal. |
| 95 |
Use of the control key as a modifier, |
| 96 |
by holding it down while pressing and releasing another key, |
| 97 |
often results in a distinct code. |
| 98 |
The behavior of other keys depends on whether |
| 99 |
.I win |
| 100 |
is in keypad mode; |
| 101 |
see subsection \*(``Keypad Mode\*('' below. |
| 102 |
.PP |
| 103 |
If no input is pending, |
| 104 |
then if the no-delay flag is set in the window |
| 105 |
(see \fB\%nodelay\fP(3NCURSES)), |
| 106 |
the function returns |
| 107 |
.BR ERR ";" |
| 108 |
otherwise, |
| 109 |
.I curses |
| 110 |
waits until the terminal has input. |
| 111 |
If \fB\%cbreak\fP(3NCURSES) or \fB\%raw\fP(3NCURSES) |
| 112 |
has been called, |
| 113 |
this happens after |
| 114 |
.I curses |
| 115 |
reads one key event. |
| 116 |
If \fB\%nocbreak\fP(3NCURSES) or \fB\%noraw\fP(3NCURSES) |
| 117 |
has been called, |
| 118 |
it occurs when |
| 119 |
.I curses |
| 120 |
reads a newline. \" "newline" because canonical mode normalizes NL/CR |
| 121 |
(Because the terminal's canonical or \*(``cooked\*('' mode |
| 122 |
is line-buffered, |
| 123 |
multiple |
| 124 |
.B \%wgetch |
| 125 |
calls may then be necessary to empty the input queue.) |
| 126 |
If \fB\%halfdelay\fP(3NCURSES) |
| 127 |
has been called, |
| 128 |
.I curses |
| 129 |
waits until input is available or the specified delay elapses. |
| 130 |
.PP |
| 131 |
If \fB\%echo\fP(3NCURSES) has been called, |
| 132 |
and the window is not a pad, |
| 133 |
.I curses |
| 134 |
writes the returned character |
| 135 |
.I c |
| 136 |
to the window |
| 137 |
(at the cursor position) |
| 138 |
per the following rules. |
| 139 |
.bP |
| 140 |
If |
| 141 |
.I c |
| 142 |
matches the terminal's erase character |
| 143 |
(see \fB\%erasechar\fP(3NCURSES)), |
| 144 |
and the cursor is not at the window's leftmost column, |
| 145 |
the cursor moves leftward one position |
| 146 |
and the new position is erased |
| 147 |
as if \fB\%wmove\fP(3NCURSES) and then \fB\%wdelch\fP(3NCURSES) were called. |
| 148 |
When the window's keypad mode is enabled |
| 149 |
(see below), |
| 150 |
.B \%KEY_LEFT |
| 151 |
and |
| 152 |
.B \%KEY_BACKSPACE |
| 153 |
are handled the same way. |
| 154 |
.bP |
| 155 |
.I curses |
| 156 |
writes any other |
| 157 |
.I c |
| 158 |
to the window, |
| 159 |
as with \fB\%wechochar\fP(3NCURSES). |
| 160 |
.bP |
| 161 |
If the window |
| 162 |
.I win |
| 163 |
has been moved or modified since the last call to |
| 164 |
\fB\%wrefresh\fP(3NCURSES), |
| 165 |
.I curses |
| 166 |
calls |
| 167 |
.B \%wrefresh |
| 168 |
on it. |
| 169 |
.PP |
| 170 |
If |
| 171 |
.I c |
| 172 |
is a carriage return and \fBnl\fP(3NCURSES) has been called, |
| 173 |
.B \%wgetch |
| 174 |
returns the character code for line feed instead. |
| 175 |
.SS "Keypad Mode" |
| 176 |
Call \fB\%keypad\fP(3NCURSES) on a window to configure keypad mode |
| 177 |
when reading input from it. |
| 178 |
In |
| 179 |
.IR "keypad mode" "," |
| 180 |
.I curses |
| 181 |
treats key strokes not from the alphabetic section of the keyboard |
| 182 |
(those corresponding to the ECMA-6 character set \(em |
| 183 |
see \fI\%ascii\fP(7) \(em |
| 184 |
optionally modified by either the control or shift keys) |
| 185 |
as |
| 186 |
.I function |
| 187 |
keys. |
| 188 |
(In |
| 189 |
.IR curses "," |
| 190 |
the term \*(``function key\*('' includes but is not limited to keycaps |
| 191 |
engraved with \*(``F1\*('', |
| 192 |
\*(``PF1\*('', |
| 193 |
and so on.) |
| 194 |
If a window is in keypad mode, |
| 195 |
.B \%wgetch |
| 196 |
translates these key strokes to a numeric code corresponding to the |
| 197 |
.B KEY_ |
| 198 |
symbols listed in subsection \*(``Key Codes\*('' below. |
| 199 |
If the window is not in keypad mode, |
| 200 |
the input queue populates with |
| 201 |
the characters of the function key's escape sequence, |
| 202 |
which the application must collect individually with multiple |
| 203 |
.B \%wgetch |
| 204 |
calls. |
| 205 |
.bP |
| 206 |
The |
| 207 |
.I \%curses.h |
| 208 |
header file declares many |
| 209 |
.I "function keys" |
| 210 |
whose names begin with |
| 211 |
.BR KEY_ ";" |
| 212 |
these object-like macros |
| 213 |
have integer values outside the range of eight-bit character codes. |
| 214 |
.bP |
| 215 |
In |
| 216 |
.IR \%ncurses "," |
| 217 |
.I "user-defined function keys" |
| 218 |
are configured with \fB\%define_key\fP(3NCURSES); |
| 219 |
they have no names, |
| 220 |
but are also expected to |
| 221 |
have integer values outside the range of eight-bit character codes. |
| 222 |
.PP |
| 223 |
A variable intended to hold a function key code must thus be of type |
| 224 |
.I short |
| 225 |
or larger. |
| 226 |
.PP |
| 227 |
Most terminals one encounters follow the ECMA-48 standard insofar as |
| 228 |
their function keys produce character sequences prefixed with the |
| 229 |
escape character ESC. |
| 230 |
This fact implies that |
| 231 |
.I curses |
| 232 |
cannot distinguish a user's press of the escape key |
| 233 |
(assuming it sends ESC) |
| 234 |
from the beginning of a function key's character sequence without |
| 235 |
waiting to see if, |
| 236 |
and how soon, |
| 237 |
further input arrives. |
| 238 |
.bP |
| 239 |
If the escape sequence |
| 240 |
matches a string capability defining a function key |
| 241 |
for the terminal type |
| 242 |
(such as |
| 243 |
.B \%key_home |
| 244 |
.RB \%( khome ) |
| 245 |
or |
| 246 |
.B \%key_up |
| 247 |
.RB \%( kuu1 )), |
| 248 |
.B \%wgetch |
| 249 |
returns the function key code corresponding to the unique sequence |
| 250 |
defined by the terminal. |
| 251 |
.bP |
| 252 |
If the escape sequence matches no function keys |
| 253 |
defined for the terminal type, |
| 254 |
call |
| 255 |
.B \%wgetch |
| 256 |
repeatedly to obtain |
| 257 |
the codes of the individual characters of the sequence, |
| 258 |
in the order they occurred in the input. |
| 259 |
.bP |
| 260 |
If |
| 261 |
.B \%wgetch |
| 262 |
cannot decide the validity of the input as a function key |
| 263 |
because it has not read enough characters to disambiguate it, |
| 264 |
the function waits until it has this information or the |
| 265 |
.I "escape delay" |
| 266 |
elapses. |
| 267 |
Configure the escape delay |
| 268 |
with the global variable |
| 269 |
.BR \%ESCDELAY "," |
| 270 |
an extension |
| 271 |
(see section \*(``EXTENSIONS\*('' below), |
| 272 |
or the environment variable of the same name |
| 273 |
(see section \*(``ENVIRONMENT\*('' of \fB\%ncurses\fP(3NCURSES)), |
| 274 |
also an extension. |
| 275 |
.PP |
| 276 |
Consequently, |
| 277 |
a user of a |
| 278 |
.I curses |
| 279 |
application that employs keypad mode |
| 280 |
may experience a pause or \*(``hang\*('' |
| 281 |
after pressing the escape key while |
| 282 |
.I curses |
| 283 |
collects sufficient characters to disambiguate the input. |
| 284 |
If the window is in \*(``no time-out\*('' mode, |
| 285 |
the escape delay is effectively infinite; |
| 286 |
see \fB\%notimeout\fP(3NCURSES). |
| 287 |
In the event of such a pause, |
| 288 |
further typing \*(``awakens\*('' |
| 289 |
.IR curses "." |
| 290 |
.SS "Ungetting Characters" |
| 291 |
.B \%ungetch |
| 292 |
places |
| 293 |
.I c |
| 294 |
into the input queue to be returned by the next call to |
| 295 |
.BR \%wgetch "." |
| 296 |
A single input queue serves all windows associated with the screen. |
| 297 |
.SS "Key Codes" |
| 298 |
The header file |
| 299 |
.I \%curses.h |
| 300 |
defines the following function key codes. |
| 301 |
.bP |
| 302 |
Except for the special case of |
| 303 |
.BR \%KEY_RESIZE "," |
| 304 |
a window's keypad mode must be enabled for |
| 305 |
.B \%wgetch |
| 306 |
to read these codes from it. |
| 307 |
.bP |
| 308 |
Not all of these are necessarily supported on any particular terminal. |
| 309 |
.bP |
| 310 |
The naming convention may seem obscure, |
| 311 |
with some apparent misspellings |
| 312 |
(such as \*(``RSUME\*('' for \*(``resume\*(''); |
| 313 |
the names correspond to the |
| 314 |
.I \%term\%info |
| 315 |
capability names for the keys, |
| 316 |
and were standardized before the IBM PC/AT keyboard layout achieved a |
| 317 |
dominant position in industry. |
| 318 |
.PP |
| 319 |
.RS |
| 320 |
.\" XXX: Move this list into ncurses(3X), rather than duplicating it in |
| 321 |
.\" get_wch(3X) or having that page cross reference this one? |
| 322 |
.TS |
| 323 |
Lb Lb |
| 324 |
Lb Lw(36n)x. |
| 325 |
Symbol Key name |
| 326 |
= |
| 327 |
KEY_BREAK Break key |
| 328 |
.ne 4 |
| 329 |
KEY_DOWN Arrow keys |
| 330 |
KEY_UP \^ |
| 331 |
KEY_LEFT \^ |
| 332 |
KEY_RIGHT \^ |
| 333 |
KEY_HOME Home key (upward+left arrow) |
| 334 |
KEY_BACKSPACE Backspace |
| 335 |
KEY_F0 T{ |
| 336 |
Function keys; space for 64 keys is reserved |
| 337 |
T} |
| 338 |
KEY_F(\fIn\fP) T{ |
| 339 |
Function key \fIn\fP where 0 \(<= \fIn\fP \(<= 63 |
| 340 |
T} |
| 341 |
KEY_DL Delete line |
| 342 |
KEY_IL Insert line |
| 343 |
KEY_DC Delete character |
| 344 |
KEY_IC Insert character/Enter insert mode |
| 345 |
KEY_EIC Exit insert character mode |
| 346 |
KEY_CLEAR Clear screen |
| 347 |
KEY_EOS Clear to end of screen |
| 348 |
KEY_EOL Clear to end of line |
| 349 |
KEY_SF Scroll one line forward |
| 350 |
KEY_SR Scroll one line backward (reverse) |
| 351 |
KEY_NPAGE Next page/Page up |
| 352 |
KEY_PPAGE Previous page/Page down |
| 353 |
KEY_STAB Set tab |
| 354 |
KEY_CTAB Clear tab |
| 355 |
KEY_CATAB Clear all tabs |
| 356 |
KEY_ENTER Enter/Send |
| 357 |
KEY_SRESET Soft (partial) reset |
| 358 |
KEY_RESET (Hard) reset |
| 359 |
KEY_PRINT Print/Copy |
| 360 |
KEY_LL Home down/Bottom (lower left) |
| 361 |
KEY_A1 Upper left of keypad |
| 362 |
KEY_A3 Upper right of keypad |
| 363 |
KEY_B2 Center of keypad |
| 364 |
KEY_C1 Lower left of keypad |
| 365 |
KEY_C3 Lower right of keypad |
| 366 |
KEY_BTAB Back tab key |
| 367 |
KEY_BEG Beg(inning) key |
| 368 |
KEY_CANCEL Cancel key |
| 369 |
KEY_CLOSE Close key |
| 370 |
KEY_COMMAND Cmd (command) key |
| 371 |
KEY_COPY Copy key |
| 372 |
KEY_CREATE Create key |
| 373 |
KEY_END End key |
| 374 |
KEY_EXIT Exit key |
| 375 |
KEY_FIND Find key |
| 376 |
KEY_HELP Help key |
| 377 |
KEY_MARK Mark key |
| 378 |
KEY_MESSAGE Message key |
| 379 |
KEY_MOUSE Mouse event occurred |
| 380 |
KEY_MOVE Move key |
| 381 |
KEY_NEXT Next object key |
| 382 |
KEY_OPEN Open key |
| 383 |
KEY_OPTIONS Options key |
| 384 |
KEY_PREVIOUS Previous object key |
| 385 |
KEY_REDO Redo key |
| 386 |
KEY_REFERENCE Ref(erence) key |
| 387 |
KEY_REFRESH Refresh key |
| 388 |
KEY_REPLACE Replace key |
| 389 |
KEY_RESIZE Screen resized |
| 390 |
KEY_RESTART Restart key |
| 391 |
KEY_RESUME Resume key |
| 392 |
KEY_SAVE Save key |
| 393 |
KEY_SELECT Select key |
| 394 |
KEY_SUSPEND Suspend key |
| 395 |
KEY_UNDO Undo key |
| 396 |
_ |
| 397 |
KEY_SBEG Shifted beginning key |
| 398 |
KEY_SCANCEL Shifted cancel key |
| 399 |
KEY_SCOMMAND Shifted command key |
| 400 |
KEY_SCOPY Shifted copy key |
| 401 |
KEY_SCREATE Shifted create key |
| 402 |
KEY_SDC Shifted delete character key |
| 403 |
KEY_SDL Shifted delete line key |
| 404 |
KEY_SEND Shifted end key |
| 405 |
KEY_SEOL Shifted clear line key |
| 406 |
KEY_SEXIT Shifted exit key |
| 407 |
KEY_SFIND Shifted find key |
| 408 |
KEY_SHELP Shifted help key |
| 409 |
KEY_SHOME Shifted home key |
| 410 |
KEY_SIC Shifted insert key |
| 411 |
KEY_SLEFT Shifted left arrow key |
| 412 |
KEY_SMESSAGE Shifted message key |
| 413 |
KEY_SMOVE Shifted move key |
| 414 |
KEY_SNEXT Shifted next object key |
| 415 |
KEY_SOPTIONS Shifted options key |
| 416 |
KEY_SPREVIOUS Shifted previous object key |
| 417 |
KEY_SPRINT Shifted print key |
| 418 |
KEY_SREDO Shifted redo key |
| 419 |
KEY_SREPLACE Shifted replace key |
| 420 |
KEY_SRIGHT Shifted right arrow key |
| 421 |
KEY_SRSUME Shifted resume key |
| 422 |
KEY_SSAVE Shifted save key |
| 423 |
KEY_SSUSPEND Shifted suspend key |
| 424 |
KEY_SUNDO Shifted undo key |
| 425 |
.TE |
| 426 |
.RE |
| 427 |
.PP |
| 428 |
Many keyboards feature a nine-key directional pad. |
| 429 |
.PP |
| 430 |
.RS |
| 431 |
.TS |
| 432 |
allbox center; |
| 433 |
C C C. |
| 434 |
A1 up A3 |
| 435 |
left B2 right |
| 436 |
C1 down C3 |
| 437 |
.TE |
| 438 |
.RE |
| 439 |
.sp |
| 440 |
Two of the symbols in the list above do |
| 441 |
.I not |
| 442 |
correspond to a physical key. |
| 443 |
.bP |
| 444 |
.B \%wgetch |
| 445 |
returns |
| 446 |
.BR \%KEY_RESIZE "," |
| 447 |
even if the window's keypad mode is disabled, |
| 448 |
if |
| 449 |
.I \%ncurses |
| 450 |
has handled a |
| 451 |
.I \%SIGWINCH |
| 452 |
signal since |
| 453 |
.B \%wgetch |
| 454 |
was called; |
| 455 |
see \fB\%initscr\fP(3NCURSES) and \fB\%resizeterm\fP(3NCURSES). |
| 456 |
.bP |
| 457 |
.B \%wgetch |
| 458 |
returns |
| 459 |
.B \%KEY_MOUSE |
| 460 |
to indicate that a mouse event is pending collection; |
| 461 |
see \fB\%mouse\fP(3NCURSES). |
| 462 |
Receipt of this code requires a window's keypad mode to be enabled, |
| 463 |
because to interpret mouse input |
| 464 |
(as with \fI\%xterm\fP(1)'s mouse protocol), |
| 465 |
.I \%ncurses |
| 466 |
must read an escape sequence, |
| 467 |
as with a function key. |
| 468 |
.SS "Testing Key Codes" |
| 469 |
In |
| 470 |
.IR \%ncurses "," |
| 471 |
.B \%has_key |
| 472 |
returns a Boolean value indicating whether the terminal type recognizes |
| 473 |
its parameter as a key code value. |
| 474 |
See also |
| 475 |
\fB\%define_key\fP(3NCURSES) and \fB\%key_defined\fP(3NCURSES). |
| 476 |
.SH RETURN VALUE |
| 477 |
.B \%wgetch |
| 478 |
returns a key code identifying the key event as described above, |
| 479 |
which may include |
| 480 |
.B \%KEY_RESIZE |
| 481 |
or |
| 482 |
.B \%KEY_MOUSE |
| 483 |
indicating non-key events, |
| 484 |
or |
| 485 |
.B ERR |
| 486 |
on failure. |
| 487 |
.B \%wgetch |
| 488 |
fails if |
| 489 |
its timeout expires without any data arriving, |
| 490 |
which cannot happen if \fB\%nodelay\fP(3NCURSES) is in effect on the window. |
| 491 |
.PP |
| 492 |
In |
| 493 |
.IR \%ncurses , |
| 494 |
.B \%wgetch |
| 495 |
also fails if |
| 496 |
.bP |
| 497 |
the |
| 498 |
.I curses |
| 499 |
screen has not been initialized, |
| 500 |
.bP |
| 501 |
(for functions taking a |
| 502 |
.I \%WINDOW |
| 503 |
pointer argument) |
| 504 |
.I win |
| 505 |
is a null pointer, |
| 506 |
or |
| 507 |
.bP |
| 508 |
execution was interrupted by a signal, |
| 509 |
in which case the library sets |
| 510 |
.I \%errno |
| 511 |
to |
| 512 |
.IR \%EINTR "." |
| 513 |
.PP |
| 514 |
Functions prefixed with \*(``mv\*('' first perform cursor movement and |
| 515 |
fail if the position |
| 516 |
.RI ( y , |
| 517 |
.IR x ")" |
| 518 |
is outside the window boundaries. |
| 519 |
.PP |
| 520 |
.B \%ungetch |
| 521 |
returns |
| 522 |
.B OK |
| 523 |
on success and |
| 524 |
.B ERR |
| 525 |
on failure. |
| 526 |
In |
| 527 |
.IR \%ncurses , |
| 528 |
.B \%ungetch |
| 529 |
fails if |
| 530 |
.bP |
| 531 |
the |
| 532 |
.I curses |
| 533 |
screen has not been initialized, |
| 534 |
or |
| 535 |
.bP |
| 536 |
there is no more room in the input queue. |
| 537 |
.PP |
| 538 |
.B \%has_key |
| 539 |
returns |
| 540 |
.B TRUE |
| 541 |
or |
| 542 |
.BR FALSE "." |
| 543 |
.SH NOTES |
| 544 |
.BR \%getch "," |
| 545 |
.BR \%mvgetch "," |
| 546 |
and |
| 547 |
.B \%mvwgetch |
| 548 |
may be implemented as macros. |
| 549 |
.PP |
| 550 |
.I curses |
| 551 |
discourages assignment of the ESC key to a discrete function by the |
| 552 |
programmer because the library requires a delay while it awaits the |
| 553 |
potential remainder of a terminal escape sequence. |
| 554 |
.PP |
| 555 |
Some key strokes are indistinguishable from control characters; |
| 556 |
for example, |
| 557 |
.B \%KEY_ENTER |
| 558 |
may be the same as |
| 559 |
.BR \*^M "," |
| 560 |
.\" as with att630 or pccon+keys |
| 561 |
and |
| 562 |
.B \%KEY_BACKSPACE |
| 563 |
may be the same as |
| 564 |
.B \*^H |
| 565 |
.\" as with att505 or vt52-basic |
| 566 |
or |
| 567 |
.BR \*^? "." |
| 568 |
.\" as with pccon+keys or vt320 |
| 569 |
Consult the |
| 570 |
.I \%term\%info |
| 571 |
entry for the terminal type to determine whether this is the case; |
| 572 |
see \fB\%infocmp\fP(1). |
| 573 |
Some |
| 574 |
.I curses |
| 575 |
implementations, |
| 576 |
including |
| 577 |
.IR \%ncurses "," |
| 578 |
honor the |
| 579 |
.I \%term\%info |
| 580 |
key definitions; |
| 581 |
others treat such control characters specially. |
| 582 |
.PP |
| 583 |
.I curses |
| 584 |
distinguishes the Enter keys in the alphabetic and numeric keypad |
| 585 |
sections of a keyboard because (most) terminals do. |
| 586 |
.B \%KEY_ENTER |
| 587 |
refers to the key on the numeric keypad and, |
| 588 |
like other function keys, |
| 589 |
is reliably recognized only if the window's keypad mode is enabled. |
| 590 |
.bP |
| 591 |
The |
| 592 |
.I \%term\%info |
| 593 |
.B \%key_enter |
| 594 |
.RB ( kent ) |
| 595 |
capability describes the character (sequence) sent by the Enter key of |
| 596 |
a terminal's numeric |
| 597 |
(or similar) |
| 598 |
keypad. |
| 599 |
.bP |
| 600 |
\*(``Enter or send\*('' is X/Open Curses's description of this key. |
| 601 |
.PP |
| 602 |
.I curses |
| 603 |
treats the Enter or Return key in the |
| 604 |
.I alphabetic |
| 605 |
section of the keyboard differently. |
| 606 |
.bP |
| 607 |
It usually produces a control code for carriage return |
| 608 |
.RB ( \*^M ) |
| 609 |
or line feed |
| 610 |
.RB ( \*^J ). |
| 611 |
.bP |
| 612 |
Depending on the terminal mode |
| 613 |
(raw, |
| 614 |
cbreak, |
| 615 |
or |
| 616 |
canonical), |
| 617 |
and whether \fB\%nl\fP(3NCURSES) or \fB\%nonl\fP(3NCURSES) has been called, |
| 618 |
.B \%wgetch |
| 619 |
may return either a carriage return or line feed upon an Enter or Return |
| 620 |
key stroke. |
| 621 |
.PP |
| 622 |
Use of |
| 623 |
.B \%wgetch |
| 624 |
with \fB\%echo\fP(3NCURSES) and neither \fB\%cbreak\fP(3NCURSES) nor \fB\%raw\fP(3NCURSES) |
| 625 |
is not well-defined. |
| 626 |
.PP |
| 627 |
Historically, |
| 628 |
the list of key code macros above was influenced by the keyboard of the |
| 629 |
AT&T 7300 |
| 630 |
(also known variously as the \*(``3B1\*('', \*(``Safari 4\*('', and |
| 631 |
\*(``UNIX PC\*(''), |
| 632 |
a 1985 machine rich in function keys. |
| 633 |
Today's computer keyboards are based on that of the IBM PC/AT |
| 634 |
and tend to have fewer. |
| 635 |
A |
| 636 |
.I curses |
| 637 |
application can expect such a keyboard to transmit key codes |
| 638 |
.BR \%KEY_UP "," |
| 639 |
.BR \%KEY_DOWN "," |
| 640 |
.BR \%KEY_LEFT "," |
| 641 |
.BR \%KEY_RIGHT "," |
| 642 |
.BR \%KEY_HOME "," |
| 643 |
.BR \%KEY_END "," |
| 644 |
.B \%KEY_PPAGE |
| 645 |
(Page Up), |
| 646 |
.B \%KEY_NPAGE |
| 647 |
(Page Down), |
| 648 |
.B \%KEY_IC |
| 649 |
(Insert), |
| 650 |
.B \%KEY_DC |
| 651 |
(Delete), |
| 652 |
.BR \%KEY_A1 "," |
| 653 |
.BR \%KEY_A3 "," |
| 654 |
.BR \%KEY_B2 "," |
| 655 |
.BR \%KEY_C1 "," |
| 656 |
.BR \%KEY_C3 "," |
| 657 |
and |
| 658 |
.BI \%KEY_F( n ) |
| 659 |
for 1 \(<= |
| 660 |
.I n |
| 661 |
\(<= 12. |
| 662 |
.\" Other numeric keypad keys from the DEC VT220 (specifically, the |
| 663 |
.\" LK201 commonly used with it) and IBM PC/AT keyboards -- the comma |
| 664 |
.\" (DEC); plus, star, and slash (PC); and zero, dot, and minus (both) |
| 665 |
.\" have no standard key capability codes. |
| 666 |
.SH EXTENSIONS |
| 667 |
In |
| 668 |
.IR \%ncurses "," |
| 669 |
when a window's \*(``no time-out\*('' mode is |
| 670 |
.I not |
| 671 |
set, |
| 672 |
the |
| 673 |
.B \%ESCDELAY |
| 674 |
variable configures the duration of the timer used to disambiguate a |
| 675 |
function key character sequence from a series of key strokes beginning |
| 676 |
with ESC typed by the user; |
| 677 |
see |
| 678 |
\fB\%curses_variables\fP(3NCURSES). |
| 679 |
.PP |
| 680 |
.B \%has_key |
| 681 |
is an |
| 682 |
.I \%ncurses |
| 683 |
extension, |
| 684 |
and is not found in SVr4 |
| 685 |
.IR curses "," |
| 686 |
4.4BSD |
| 687 |
.IR curses "," |
| 688 |
or any other previous |
| 689 |
.I curses |
| 690 |
implementation. |
| 691 |
.SH PORTABILITY |
| 692 |
Applications employing |
| 693 |
.I \%ncurses |
| 694 |
extensions should condition their use on the visibility of the |
| 695 |
.B \%NCURSES_VERSION |
| 696 |
preprocessor macro. |
| 697 |
.PP |
| 698 |
Except as noted in section \*(``EXTENSIONS\*('' above, |
| 699 |
X/Open Curses Issue\ 4 describes these functions. |
| 700 |
It specifies no error conditions for them. |
| 701 |
.PP |
| 702 |
SVr4 describes a successful return value only as |
| 703 |
\*(``an integer value other than |
| 704 |
.IR ERR \*(''. \" Courier roman in source; SVID 4, vol. 3, p. 494 |
| 705 |
.PP |
| 706 |
.I \%wgetch |
| 707 |
reads only single-byte characters. |
| 708 |
.PP |
| 709 |
The echo behavior of these functions on input of |
| 710 |
.I KEY_ |
| 711 |
or backspace characters is not documented in SVr4 |
| 712 |
.IR curses "." |
| 713 |
.PP |
| 714 |
The behavior of |
| 715 |
.I \%wgetch |
| 716 |
in the presence of signal handlers is not documented in SVr4 |
| 717 |
.I curses |
| 718 |
and is unspecified by X/Open Curses. |
| 719 |
In historical |
| 720 |
.I curses |
| 721 |
implementations, |
| 722 |
it varied depending on whether the operating system's dispatch of a |
| 723 |
signal to a handler interrupted a \fIread\fP(2) call in progress, |
| 724 |
and also |
| 725 |
(in some implementations) |
| 726 |
whether an input timeout or non-blocking mode had been set. |
| 727 |
A portable |
| 728 |
.I curses |
| 729 |
application prepares for two cases: |
| 730 |
(a) signal receipt does not interrupt |
| 731 |
.IR \%wgetch ";" |
| 732 |
and |
| 733 |
(b) signal receipt interrupts |
| 734 |
.I \%wgetch |
| 735 |
and causes it to return |
| 736 |
.I ERR |
| 737 |
with |
| 738 |
.I \%errno |
| 739 |
set to |
| 740 |
.IR \%EINTR "." |
| 741 |
.PP |
| 742 |
.I \%KEY_MOUSE |
| 743 |
is mentioned in X/Open Curses, |
| 744 |
along with a few related |
| 745 |
.I \%term\%info |
| 746 |
capabilities, |
| 747 |
but no higher-level functions use the feature. |
| 748 |
The implementation in |
| 749 |
.I \%ncurses |
| 750 |
is an extension. |
| 751 |
.PP |
| 752 |
.I \%KEY_RESIZE |
| 753 |
and |
| 754 |
.I \%has_key |
| 755 |
are extensions first implemented for |
| 756 |
.IR \%ncurses "." |
| 757 |
By 2022, |
| 758 |
.I \%PDCurses |
| 759 |
.\" https://web.archive.org/web/20220117232009/https://pdcurses.org/docs/MANUAL.html |
| 760 |
and |
| 761 |
NetBSD |
| 762 |
.I curses |
| 763 |
.\" https://web.archive.org/web/20200923185647/https://man.netbsd.org/curses_input.3 |
| 764 |
had added them along with |
| 765 |
.IR \%KEY_MOUSE "." |
| 766 |
.SH HISTORY |
| 767 |
4BSD (1980) |
| 768 |
introduced |
| 769 |
.I \%wgetch |
| 770 |
and its variants. |
| 771 |
.PP |
| 772 |
SVr3 (1987) |
| 773 |
added |
| 774 |
.IR \%ungetch "." |
| 775 |
.PP |
| 776 |
.I \%ncurses |
| 777 |
1.9.9g (1996) |
| 778 |
furnished the |
| 779 |
.I \%has_key |
| 780 |
extension. |
| 781 |
.SH SEE ALSO |
| 782 |
ECMA-6 \*(``7-bit coded Character Set\*('' |
| 783 |
\%<https://\*:ecma\-international\*:.org/\ |
| 784 |
\*:publications\-and\-standards/\*:standards/\*:ecma\-6/> |
| 785 |
.PP |
| 786 |
ECMA-48 \*(``Control Functions for Coded Character Sets\*('' |
| 787 |
\%<https://\*:ecma\-international\*:.org/\ |
| 788 |
\*:publications\-and\-standards/\*:standards/\*:ecma\-48/> |
| 789 |
.PP |
| 790 |
\fB\%get_wch\fP(3NCURSES) describes comparable functions of the |
| 791 |
.I \%ncurses |
| 792 |
library in its wide-character configuration |
| 793 |
.RI \%( ncursesw ). |
| 794 |
.PP |
| 795 |
\fB\%ncurses\fP(3NCURSES), |
| 796 |
\fB\%addch\fP(3NCURSES), |
| 797 |
\fB\%inopts\fP(3NCURSES), |
| 798 |
\fB\%mouse\fP(3NCURSES), |
| 799 |
\fB\%move\fP(3NCURSES), |
| 800 |
\fB\%outopts\fP(3NCURSES), |
| 801 |
\fB\%refresh\fP(3NCURSES), |
| 802 |
\fB\%curses_variables\fP(3NCURSES), |
| 803 |
\fB\%resizeterm\fP(3NCURSES), |
| 804 |
\fB\%ascii\fP(7) |