| 1 |
.\"*************************************************************************** |
| 2 |
.\" Copyright 2018-2024,2025 Thomas E. Dickey * |
| 3 |
.\" Copyright 2002-2016,2017 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_get_wch.3x,v 1.71 2025/08/16 19:11:47 tom Exp $ |
| 31 |
.TH get_wch 3NCURSES 2025-08-16 "ncurses 6.6" "Library calls" |
| 32 |
.ie \n(.g \{\ |
| 33 |
.ds `` \(lq |
| 34 |
.ds '' \(rq |
| 35 |
.\} |
| 36 |
.el \{\ |
| 37 |
.ie t .ds `` `` |
| 38 |
.el .ds `` "" |
| 39 |
.ie t .ds '' '' |
| 40 |
.el .ds '' "" |
| 41 |
.\} |
| 42 |
. |
| 43 |
.de bP |
| 44 |
.ie n .IP \(bu 4 |
| 45 |
.el .IP \(bu 2 |
| 46 |
.. |
| 47 |
.SH NAME |
| 48 |
\fB\%get_wch\fP, |
| 49 |
\fB\%wget_wch\fP, |
| 50 |
\fB\%mvget_wch\fP, |
| 51 |
\fB\%mvwget_wch\fP, |
| 52 |
\fB\%unget_wch\fP \- |
| 53 |
get (or push back) a wide character from \fIcurses\fR terminal keyboard buffer |
| 54 |
.SH SYNOPSIS |
| 55 |
.nf |
| 56 |
\fB#include <curses.h> |
| 57 |
.PP |
| 58 |
\fBint get_wch(wint_t * \fIwch\fP); |
| 59 |
\fBint wget_wch(WINDOW * \fIwin\fP, wint_t * \fIwch\fP); |
| 60 |
\fBint mvget_wch(int \fIy\fP, int \fIx\fP, wint_t * \fIwch\fP); |
| 61 |
\fBint mvwget_wch(WINDOW * \fIwin\fP, int \fIy\fP, int \fIx\fP, wint_t * \fIwch\fP); |
| 62 |
.PP |
| 63 |
\fBint unget_wch(const wchar_t \fIwc\fP); |
| 64 |
.fi |
| 65 |
.SH DESCRIPTION |
| 66 |
.SS "Reading Characters" |
| 67 |
.B \%wget_wch |
| 68 |
gathers a key event from the terminal keyboard associated with a |
| 69 |
.I curses |
| 70 |
window |
| 71 |
.IR win "," |
| 72 |
returning |
| 73 |
.B OK |
| 74 |
if a wide character is read, |
| 75 |
.B \%KEY_CODE_YES |
| 76 |
if a function key is read, |
| 77 |
and |
| 78 |
.B ERR |
| 79 |
if no key event is available. |
| 80 |
\fB\%ncurses\fP(3NCURSES) describes the variants of this function. |
| 81 |
.PP |
| 82 |
When input is pending, |
| 83 |
.B \%wget_wch |
| 84 |
stores an integer |
| 85 |
identifying the key event in |
| 86 |
.IR wch ";" |
| 87 |
for alphanumeric and punctuation keys, |
| 88 |
this value corresponds to the character encoding used by the terminal. |
| 89 |
Use of the control key as a modifier, |
| 90 |
by holding it down while pressing and releasing another key, |
| 91 |
often results in a distinct code. |
| 92 |
The behavior of other keys depends on whether |
| 93 |
.I win |
| 94 |
is in keypad mode; |
| 95 |
see subsections \*(``Keypad Mode\*('' and \*(``Key Codes\*('' |
| 96 |
in \fB\%getch\fP(3NCURSES). |
| 97 |
.PP |
| 98 |
If no input is pending, |
| 99 |
then if the no-delay flag is set in the window |
| 100 |
(see \fB\%nodelay\fP(3NCURSES)), |
| 101 |
the function returns |
| 102 |
.BR ERR ";" |
| 103 |
otherwise, |
| 104 |
.I curses |
| 105 |
waits until the terminal has input. |
| 106 |
If \fB\%cbreak\fP(3NCURSES) or \fB\%raw\fP(3NCURSES) |
| 107 |
has been called, |
| 108 |
this happens after one character is read. |
| 109 |
If \fB\%nocbreak\fP(3NCURSES) or \fB\%noraw\fP(3NCURSES) |
| 110 |
has been called, |
| 111 |
it occurs when the next newline is read. |
| 112 |
(Because the terminal's canonical or \*(``cooked\*('' mode |
| 113 |
is line-buffered, |
| 114 |
multiple |
| 115 |
.B \%wget_wch |
| 116 |
calls may then be necessary to empty the input queue.) |
| 117 |
If \fB\%halfdelay\fP(3NCURSES) |
| 118 |
has been called, |
| 119 |
.I curses |
| 120 |
waits until input is available or the specified delay elapses. |
| 121 |
.PP |
| 122 |
If \fB\%echo\fP(3NCURSES) has been called, |
| 123 |
and the window is not a pad, |
| 124 |
.I curses |
| 125 |
writes the wide character |
| 126 |
from the input queue |
| 127 |
to the window |
| 128 |
(at the cursor position) |
| 129 |
per the following rules. |
| 130 |
.bP |
| 131 |
If the wide character |
| 132 |
matches the terminal's erase character |
| 133 |
(see \fB\%erasewchar\fP(3NCURSES)), |
| 134 |
the cursor moves leftward one position |
| 135 |
and the new position is erased |
| 136 |
as if \fB\%wmove\fP(3NCURSES) and then \fB\%wdelch\fP(3NCURSES) were called. |
| 137 |
When the window's keypad mode is enabled |
| 138 |
(see below), |
| 139 |
.B \%KEY_LEFT |
| 140 |
and |
| 141 |
.B \%KEY_BACKSPACE |
| 142 |
are handled the same way. |
| 143 |
.bP |
| 144 |
.I curses |
| 145 |
writes any other |
| 146 |
wide character |
| 147 |
to the window, |
| 148 |
as with \fB\%wecho_wchar\fP(3NCURSES). |
| 149 |
.bP |
| 150 |
If the window |
| 151 |
.I win |
| 152 |
has been moved or modified since the last call to |
| 153 |
\fB\%wrefresh\fP(3NCURSES), |
| 154 |
.I curses |
| 155 |
calls |
| 156 |
.B \%wrefresh |
| 157 |
on it. |
| 158 |
.PP |
| 159 |
If the wide character |
| 160 |
is a carriage return and \fBnl\fP(3NCURSES) has been called, |
| 161 |
.B \%wget_wch |
| 162 |
stores the wide character code for line feed in |
| 163 |
.I wch |
| 164 |
instead. |
| 165 |
.SS "Ungetting Characters" |
| 166 |
.B \%unget_wch |
| 167 |
places |
| 168 |
.I wc |
| 169 |
into the input queue to be retrieved by the next call to |
| 170 |
.BR \%wget_wch "." |
| 171 |
A single input queue serves all windows associated with the screen. |
| 172 |
.SH RETURN VALUE |
| 173 |
.B \%wget_wch |
| 174 |
returns |
| 175 |
.B OK |
| 176 |
when it reads a wide character, |
| 177 |
.B \%KEY_CODE_YES |
| 178 |
when it reads a function key code, |
| 179 |
and |
| 180 |
.B ERR |
| 181 |
on failure. |
| 182 |
.B \%wget_wch |
| 183 |
fails if |
| 184 |
its timeout expires without any data arriving, |
| 185 |
which cannot happen if \fB\%nodelay\fP(3NCURSES) is in effect on the window. |
| 186 |
.PP |
| 187 |
In |
| 188 |
.IR \%ncurses , |
| 189 |
.B \%wget_wch |
| 190 |
also fails if |
| 191 |
.bP |
| 192 |
the |
| 193 |
.I curses |
| 194 |
screen has not been initialized, |
| 195 |
.bP |
| 196 |
(for functions taking a |
| 197 |
.I \%WINDOW |
| 198 |
pointer argument) |
| 199 |
.I win |
| 200 |
is a null pointer, |
| 201 |
or |
| 202 |
.bP |
| 203 |
execution was interrupted by a signal, |
| 204 |
in which case |
| 205 |
.I \%errno |
| 206 |
is set to |
| 207 |
.IR \%EINTR "." |
| 208 |
.PP |
| 209 |
Functions prefixed with \*(``mv\*('' first perform cursor movement and |
| 210 |
fail if the position |
| 211 |
.RI ( y , |
| 212 |
.IR x ")" |
| 213 |
is outside the window boundaries. |
| 214 |
.PP |
| 215 |
.B \%unget_wch |
| 216 |
returns |
| 217 |
.B OK |
| 218 |
on success and |
| 219 |
.B ERR |
| 220 |
on failure. |
| 221 |
In |
| 222 |
.IR \%ncurses , |
| 223 |
.B \%unget_wch |
| 224 |
fails if |
| 225 |
.bP |
| 226 |
the |
| 227 |
.I curses |
| 228 |
screen has not been initialized, |
| 229 |
or |
| 230 |
.bP |
| 231 |
there is no more room in the input queue. |
| 232 |
.SH NOTES |
| 233 |
See the \*(``NOTES\*('' section of \fB\%wgetch\fP(3NCURSES). |
| 234 |
.PP |
| 235 |
All of these functions except |
| 236 |
.B \%wget_wch |
| 237 |
and |
| 238 |
.B \%unget_wch |
| 239 |
may be implemented as macros. |
| 240 |
.PP |
| 241 |
Unlike \fB\%wgetch\fP(3NCURSES), |
| 242 |
.B \%wget_wch |
| 243 |
stores the value of the input character in an additional |
| 244 |
.I wch |
| 245 |
parameter instead of the return value. |
| 246 |
.PP |
| 247 |
Unlike |
| 248 |
.BR \%ungetch "," |
| 249 |
.B \%unget_wch |
| 250 |
cannot distinguish function key codes from conventional character codes. |
| 251 |
An application can overcome this limitation by pushing function key |
| 252 |
codes with |
| 253 |
.B \%ungetch |
| 254 |
and subsequently checking the return value of |
| 255 |
.B \%wget_wch |
| 256 |
for a match with |
| 257 |
.BR \%KEY_CODE_YES "." |
| 258 |
.SH EXTENSIONS |
| 259 |
See the \*(``EXTENSIONS\*('' section of \fB\%wgetch\fP(3NCURSES). |
| 260 |
.SH PORTABILITY |
| 261 |
Applications employing |
| 262 |
.I \%ncurses |
| 263 |
extensions should condition their use on the visibility of the |
| 264 |
.B \%NCURSES_VERSION |
| 265 |
preprocessor macro. |
| 266 |
.PP |
| 267 |
X/Open Curses Issue\ 4 describes these functions. |
| 268 |
It specifies no error conditions for them. |
| 269 |
.PP |
| 270 |
See the \*(``PORTABILITY\*('' section of \fB\%wgetch\fP(3NCURSES) regarding |
| 271 |
the interaction of |
| 272 |
.I \%wget_wch |
| 273 |
with signal handlers. |
| 274 |
.SH HISTORY |
| 275 |
X/Open Curses Issue\ 4 (1995) initially specified these functions. |
| 276 |
The System\ V Interface Definition Version\ 4 |
| 277 |
of the same year |
| 278 |
specified functions named |
| 279 |
.I \%wgetwch |
| 280 |
(with its variants) |
| 281 |
.IR \%ungetwch "." |
| 282 |
.\" SVID 4, vol 3., pp. 496-499 |
| 283 |
These were later additions to |
| 284 |
.RI SVr4. x , |
| 285 |
not appearing in the first SVr4 (1989). |
| 286 |
They differ from X/Open's later |
| 287 |
.I \%wget_wch |
| 288 |
and |
| 289 |
.I \%unget_wch |
| 290 |
in that |
| 291 |
.I \%wgetwch |
| 292 |
takes no |
| 293 |
.I wch |
| 294 |
argument, |
| 295 |
but returns the (wide) key code as an |
| 296 |
.I int |
| 297 |
(with no provision for distinguishing a character code |
| 298 |
from a function key code); |
| 299 |
and |
| 300 |
.I \%ungetwch |
| 301 |
takes a |
| 302 |
.RI non- const |
| 303 |
.I int |
| 304 |
argument. |
| 305 |
.SH SEE ALSO |
| 306 |
\fB\%getch\fP(3NCURSES) describes comparable functions of the |
| 307 |
.I \%ncurses |
| 308 |
library in its non-wide-character configuration. |
| 309 |
.PP |
| 310 |
\fB\%ncurses\fP(3NCURSES), |
| 311 |
\fB\%add_wch\fP(3NCURSES), |
| 312 |
\fB\%inopts\fP(3NCURSES), |
| 313 |
\fB\%move\fP(3NCURSES), |
| 314 |
\fB\%refresh\fP(3NCURSES) |