blob: 02932b91a6e4ebd0f97a8e6bdf06ff67e8f3c40d [file] [log] [blame]
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301.\"***************************************************************************
micky3879b9f5e72025-07-08 18:04:53 -04002.\" Copyright 2018-2023,2024 Thomas E. Dickey *
3.\" Copyright 2002-2016,2017 Free Software Foundation, Inc. *
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05304.\" *
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.\"
micky3879b9f5e72025-07-08 18:04:53 -040030.\" $Id: curs_get_wch.3x,v 1.40 2024/04/20 19:23:03 tom Exp $
31.TH curs_get_wch 3X 2024-04-20 "ncurses @NCURSES_MAJOR@.@NCURSES_MINOR@" "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..
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053047.SH NAME
micky3879b9f5e72025-07-08 18:04:53 -040048\fB\%get_wch\fP,
49\fB\%wget_wch\fP,
50\fB\%mvget_wch\fP,
51\fB\%mvwget_wch\fP,
52\fB\%unget_wch\fP \-
53get (or push back) a wide character from \fIcurses\fR terminal keyboard
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053054.SH SYNOPSIS
micky3879b9f5e72025-07-08 18:04:53 -040055.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
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053065.SH DESCRIPTION
micky3879b9f5e72025-07-08 18:04:53 -040066.SS "Reading Characters"
67.B \%wget_wch
68gathers a key stroke
69.I wch
70from the terminal keyboard associated with a
71.I curses
72window
73.IR win ,
74returning
75.B OK
76if a wide character is read,
77.B \%KEY_CODE_YES
78if a function key is read,
79and
80.B ERR
81if no key event is available.
82\fB\%ncurses\fP(3X) describes the variants of this function.
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053083.PP
micky3879b9f5e72025-07-08 18:04:53 -040084When input is pending,
85.B \%wget_wch
86stores an integer
87identifying the key stroke in
88.IR wch ;
89for alphanumeric and punctuation keys,
90this value corresponds to the character encoding used by the terminal.
91Use of the control key as a modifier often results in a distinct code.
92The behavior of other keys depends on whether
93.I win
94is in keypad mode;
95see subsections \*(``Keypad Mode\*('' and \*(``Predefined Key Codes\*(''
96in \fB\%getch\fP(3X).
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053097.PP
micky3879b9f5e72025-07-08 18:04:53 -040098If no input is pending,
99then if the no-delay flag is set in the window
100(see \fB\%nodelay\fP(3X)),
101the function returns
102.BR ERR ;
103otherwise,
104.I curses
105waits until the terminal has input.
106If \fB\%cbreak\fP(3X)
107has been called,
108this happens after one character is read.
109If \fB\%nocbreak\fP(3X)
110has been called,
111it occurs when the next newline is read.
112If \fB\%halfdelay\fP(3X)
113has been called,
114.I curses
115waits until a character is typed or the specified delay elapses.
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530116.PP
micky3879b9f5e72025-07-08 18:04:53 -0400117If \fB\%echo\fP(3X) has been called,
118and the window is not a pad,
119.I curses
120writes
121.I wch
122to the window
123(at the cursor position)
124per the following rules.
125.bP
126If
127.I wch
128matches the terminal's erase character,
129the cursor moves leftward one position
130and the new position is erased
131as if \fB\%wmove\fP(3X) and then \fB\%wdelch\fP(3X) were called.
132When the window's keypad mode is enabled
133(see below),
134.B \%KEY_LEFT
135and
136.B \%KEY_BACKSPACE
137are handled the same way.
138.bP
139.I curses
140writes any other
141.I wch
142to the window,
143as with \fB\%wecho_wchar\fP(3X).
144.bP
145If the window has been moved or modified since the last call to
146\fB\%wrefresh\fP(3X),
147.I curses
148calls
149.BR \%wrefresh .
150.PP
151If
152.I wch
153is a carriage return and \fBnl\fP(3X) has been called,
154.B \%wgetch
155stores the the character code for newline
156(line feed)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530157in
micky3879b9f5e72025-07-08 18:04:53 -0400158.I wch
159instead.
160.SS "Ungetting Characters"
161.B \%unget_wch
162places
163.I wch
164into the input queue to be returned by the next call to
165.BR \%wget_wch .
166A single input queue serves all windows.
Steve Kondikae271bc2015-11-15 02:50:53 +0100167.SH RETURN VALUE
micky3879b9f5e72025-07-08 18:04:53 -0400168.B \%wget_wch
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530169returns
micky3879b9f5e72025-07-08 18:04:53 -0400170.B OK
171when it reads a wide character and
172.B \%KEY_CODE_YES
173when it reads a function key code.
174It returns
175.B ERR
176if
177.bP
178the
179.I \%WINDOW
180pointer is
181.BR NULL ,
182or
183.bP
184its timeout expires without any data arriving,
185or
186.bP
187execution was interrupted by a signal,
188in which case
189.B \%errno
190is set to
191.BR \%EINTR .
Steve Kondikae271bc2015-11-15 02:50:53 +0100192.PP
micky3879b9f5e72025-07-08 18:04:53 -0400193Functions prefixed with \*(``mv\*('' first perform cursor movement and
194fail if the position
195.RI ( y ,
196.IR x )
197is outside the window boundaries.
198.PP
199.B \%unget_wch
200returns
201.B OK
202on success and
203.B ERR
204if there is no more room in the input queue.
205.SH NOTES
206See the \*(``NOTES\*('' section of \fB\%wgetch\fP(3X).
207.PP
208All of these functions except
209.B \%wget_wch
210and
211.B \%unget_wch
212may be implemented as macros.
213.PP
214Unlike \fB\%wgetch\fP(3X),
215.B \%wget_wch
216and its variants store the value of the input character in an additional
217.I wch
218parameter instead of the return value.
219.PP
220Unlike
221.BR \%ungetch ,
222.B \%unget_wch
223cannot distinguish function key codes
224.B \%wget_wch
225from conventional character codes.
226An application can overcome this limitation by pushing function key
227codes with
228.B \%ungetch
229and subsequently checking the return value of
230.B \%wget_wch
231for a match with
232.BR \%KEY_CODE_YES .
233.SH EXTENSIONS
234See the \*(``EXTENSIONS\*('' section of \fB\%wgetch\fP(3X).
235.SH PORTABILITY
236Applications employing
237.I \%ncurses
238extensions should condition their use on the visibility of the
239.B \%NCURSES_VERSION
240preprocessor macro.
241.PP
242X/Open Curses,
243Issue 4 describes these functions.
244It specifies no error conditions for them.
245.PP
246See the \*(``PORTABILITY\*('' section of \fB\%wgetch\fP(3X) regarding
247the interaction of
248.B \%wget_wch
249with signal handlers.
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530250.SH SEE ALSO
micky3879b9f5e72025-07-08 18:04:53 -0400251\fB\%curs_getch\fP(3X) describes comparable functions of the
252.I \%ncurses
253library in its non-wide-character configuration.
254.PP
255\fB\%curses\fP(3X),
256\fB\%curs_add_wch\fP(3X),
257\fB\%curs_inopts\fP(3X),
258\fB\%curs_move\fP(3X),
259\fB\%curs_refresh\fP(3X)