2 .\"***************************************************************************
3 .\" Copyright 2018-2023,2024 Thomas E. Dickey *
4 .\" Copyright 1998-2015,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_mouse.3x,v 1.86 2024/01/13 22:05:39 tom Exp $
32 .TH curs_mouse 3X 2024-01-13 "ncurses 6.4" "Library calls"
56 \fB\%mouseinterval\fP \-
57 get mouse events in \fIcurses\fR
60 \fB#include <curses.h>
62 \fBtypedef unsigned long mmask_t;
65 \fB short id; \fI/* ID to distinguish multiple devices */
66 \fB int x, y, z; \fI/* event coordinates */
67 \fB mmask_t bstate; \fI/* button state bits */
70 \fBbool has_mouse(void);
72 \fBint getmouse(MEVENT *\fIevent\fP);
73 \fBint ungetmouse(MEVENT *\fIevent\fP);
75 \fBmmask_t mousemask(mmask_t \fInewmask\fP, mmask_t *\fIoldmask\fP);
77 \fBbool wenclose(const WINDOW *\fIwin\fP, int \fIy\fP, int \fIx\fP);
79 \fBbool mouse_trafo(int* \fIpY\fP, int* \fIpX\fP, bool \fIto_screen\fP);
80 \fBbool wmouse_trafo(const WINDOW* \fIwin\fP,
81 \fBint* \fIpY\fB, int* \fIpX\fB, bool \fIto_screen\fB);\fR
83 \fBint mouseinterval(int \fIerval\fB);\fR
86 These functions provide an interface to mouse events from
88 Mouse events are represented by \fB\%KEY_MOUSE\fP
89 pseudo-key values in the \fB\%wgetch\fP(3X) input stream.
91 To make mouse events visible, use the \fB\%mousemask\fP function.
92 This sets the mouse events to be reported.
93 By default, no mouse events are reported.
95 The function returns an updated copy of \fInewmask\fP
96 to indicate which of the specified mouse events can be reported.
98 If the screen has not been initialized,
99 or if the terminal does not support mouse-events,
100 this function returns 0.
102 If \fIoldmask\fP is non-\fBNULL\fP,
103 this function fills the indicated location with the previous value of the
104 current screen's mouse event mask.
106 As a side effect, setting a zero mousemask may turn off the mouse pointer;
107 setting a nonzero mask may turn it on.
108 Whether this happens is device-dependent.
110 Here are the mouse event type masks which may be defined:
117 BUTTON1_PRESSED mouse button 1 down
118 BUTTON1_RELEASED mouse button 1 up
119 BUTTON1_CLICKED mouse button 1 clicked
120 BUTTON1_DOUBLE_CLICKED mouse button 1 double clicked
121 BUTTON1_TRIPLE_CLICKED mouse button 1 triple clicked
123 BUTTON2_PRESSED mouse button 2 down
124 BUTTON2_RELEASED mouse button 2 up
125 BUTTON2_CLICKED mouse button 2 clicked
126 BUTTON2_DOUBLE_CLICKED mouse button 2 double clicked
127 BUTTON2_TRIPLE_CLICKED mouse button 2 triple clicked
129 BUTTON3_PRESSED mouse button 3 down
130 BUTTON3_RELEASED mouse button 3 up
131 BUTTON3_CLICKED mouse button 3 clicked
132 BUTTON3_DOUBLE_CLICKED mouse button 3 double clicked
133 BUTTON3_TRIPLE_CLICKED mouse button 3 triple clicked
135 BUTTON4_PRESSED mouse button 4 down
136 BUTTON4_RELEASED mouse button 4 up
137 BUTTON4_CLICKED mouse button 4 clicked
138 BUTTON4_DOUBLE_CLICKED mouse button 4 double clicked
139 BUTTON4_TRIPLE_CLICKED mouse button 4 triple clicked
141 BUTTON5_PRESSED mouse button 5 down
142 BUTTON5_RELEASED mouse button 5 up
143 BUTTON5_CLICKED mouse button 5 clicked
144 BUTTON5_DOUBLE_CLICKED mouse button 5 double clicked
145 BUTTON5_TRIPLE_CLICKED mouse button 5 triple clicked
148 shift was down during button state change
151 control was down during button state change
154 alt was down during button state change
156 ALL_MOUSE_EVENTS report all button state changes
157 REPORT_MOUSE_POSITION report mouse movement
161 Once a class of mouse events has been made visible in a window,
162 calling the \fB\%wgetch\fP function on that window may return
163 \fB\%KEY_MOUSE\fP as an indicator that a mouse event has been queued.
164 To read the event data and pop the event off the queue, call
166 This function will return \fBOK\fP if a mouse event
167 is actually visible in the given window, \fBERR\fP otherwise.
168 When \fB\%getmouse\fP returns \fBOK\fP, the data deposited as y and
169 x in the event structure coordinates will be screen-relative character-cell
171 The returned state mask will have exactly one bit set to
172 indicate the event type.
173 The corresponding data in the queue is marked invalid.
174 A subsequent call to \fB\%getmouse\fP will retrieve the next older
177 The \fB\%ungetmouse\fP function behaves analogously to \fB\%ungetch\fP.
179 a \fB\%KEY_MOUSE\fP event onto the input queue, and associates with that event
180 the given state data and screen-relative character-cell coordinates.
182 The \fB\%wenclose\fP function tests whether a given pair of screen-relative
183 character-cell coordinates is enclosed by a given window, returning \fBTRUE\fP
184 if it is and \fBFALSE\fP otherwise.
185 It is useful for determining what subset of
186 the screen windows enclose the location of a mouse event.
188 The \fB\%wmouse_trafo\fP function transforms a given pair of coordinates
189 from \fB\%stdscr\fP-relative coordinates
190 to coordinates relative to the given window or vice versa.
191 The resulting \fB\%stdscr\fP-relative coordinates are not always
192 identical to window-relative coordinates due to the mechanism to reserve
193 lines on top or bottom of the screen for other purposes
194 (see the \fB\%ripoffline\fP and \fB\%slk_init\fP(3X) calls, for example).
196 If the parameter \fIto_screen\fP is \fBTRUE\fP, the pointers
197 \fIpY, pX\fP must reference the coordinates of a location
198 inside the window \fIwin\fP.
199 They are converted to window-relative coordinates and returned
200 through the pointers.
201 If the conversion was successful, the function returns \fBTRUE\fP.
203 If one of the parameters was \fBNULL\fP or the location is
204 not inside the window, \fBFALSE\fP is returned.
206 If \fIto_screen\fP is
207 \fBFALSE\fP, the pointers \fIpY, pX\fP must reference window-relative
209 They are converted to \fB\%stdscr\fP-relative coordinates if the
210 window \fIwin\fP encloses this point.
211 In this case the function returns \fBTRUE\fP.
213 If one of the parameters is \fBNULL\fP or the point is not inside the
214 window, \fBFALSE\fP is returned.
215 The referenced coordinates
216 are only replaced by the converted coordinates if the transformation was
219 The \fB\%mouse_trafo\fP function performs the same translation
220 as \fB\%wmouse_trafo\fP,
221 using \fB\%stdscr\fP for \fIwin\fP.
223 The \fB\%mouseinterval\fP function sets the maximum time (in thousands of a
224 second) that can elapse between press and release events for them to
225 be recognized as a click.
226 Use \fB\%mouseinterval(0)\fP to disable click resolution.
227 This function returns the previous interval value.
228 Use \fB\%mouseinterval(\-1)\fP to obtain the interval without altering it.
229 The default is one sixth of a second.
231 The \fB\%has_mouse\fP function returns \fBTRUE\fP if the mouse driver
232 has been successfully initialized,
233 and \fBFALSE\fP otherwise.
235 Note that mouse events will be ignored when input is in cooked mode, and will
236 cause an error beep when cooked mode is being simulated in a window by a
237 function such as \fB\%getstr\fP that expects a linefeed for input-loop
245 return \fBTRUE\fP or \fBFALSE\fP as noted above.
247 \fB\%getmouse\fP and \fB\%ungetmouse\fP
248 return \fBERR\fP upon failure and \fBOK\fP upon success.
250 \fB\%getmouse\fP fails if:
252 no mouse driver was initialized,
254 the mask of reportable events is zero,
256 a mouse event was detected that does not match the mask,
258 or if no more events remain in the queue.
260 \fB\%ungetmouse\fP returns an error if the event queue is full.
263 returns the mask of reportable events.
265 \fB\%mouseinterval\fP
266 returns the previous interval value, unless
267 the terminal was not initialized.
268 In that case, it returns the maximum interval value (166).
270 The order of the \fB\%MEVENT\fP structure members is not guaranteed.
271 Additional fields may be added to the structure in the future.
275 these calls are implemented using either
277 built-in mouse-tracking API or
278 platform-specific drivers including
281 Alessandro Rubini's gpm server
288 If you are using an unsupported configuration,
289 mouse events will not be visible to
290 \fI\%ncurses\fP (and the \fB\%mousemask\fP function will always
295 entry contains a \fBXM\fP string,
298 mouse driver to control the
299 way the terminal is initialized for mouse operation.
300 The default, if \fBXM\fP is not found,
301 corresponds to private mode 1000 of
305 \eE[?1000%?%p1%{1}%=%th%el%;
308 The mouse driver also recognizes a newer
314 \eE[?1006;1000%?%p1%{1}%=%th%el%;
317 The \fIz\fP member in the event structure is not presently used.
319 for use with touch screens (which may be pressure-sensitive) or with
320 3D-mice/trackballs/power gloves.
322 The \fB\%ALL_MOUSE_EVENTS\fP class does not
323 include \fB\%REPORT_MOUSE_POSITION\fP.
328 wheel/scrolling mice send position reports as a sequence of
329 presses of buttons 4 or 5 without matching button-releases.
331 These functions were designed for
333 and are not found in SVr4
337 or any other previous curses implementation.
343 which took no argument and returned a different type.)
345 Applications employing the
347 mouse extension should condition its use on the visibility of the
348 .B \%NCURSES_MOUSE_VERSION
350 When the interface changes,
351 the macro's value increments.
352 Multiple versions are available when
355 see section \*(``ALTERNATE CONFIGURATIONS\*('' of \fB\%ncurses\fP(3X).
356 The following values may be specified.
360 has definitions for reserved events.
361 The mask uses 28 bits.
364 adds definitions for button 5,
365 removes the definitions for reserved events.
366 The mask uses 29 bits.
371 had support for the mouse in a variant of \fI\%xterm\fP(1).
372 It is mentioned in a few places,
373 with little supporting documentation.
375 Its \*(``libcurses\*('' manual page lists functions for this feature
376 prototyped in \fI\%curses.h\fP.
380 extern int mouse_set(long int);
381 extern int mouse_on(long int);
382 extern int mouse_off(long int);
383 extern int request_mouse_pos(void);
384 extern int map_button(unsigned long);
385 extern void wmouse_position(WINDOW *, int *, int *);
386 extern unsigned long getmouse(void), getbmap(void);
390 Its \*(``terminfo\*('' manual page lists capabilities for the feature.
391 .\" These don't appear in in the SVID 4th edition, Volume 3,
392 .\" terminfo(TI_ENV) man page. They can be found in, e.g., the "z/OS
393 .\" V1R1.0 C Curses" book, Chapter 17, pp. 179-186 (PDF 213-220).
398 Number of buttons on the mouse
401 Curses should get button events
403 key_mouse kmous Km T{
404 0631, Mouse event has occurred
406 mouse_info minfo Mi T{
407 Mouse status information
409 req_mouse_pos reqmp RQ T{
410 Request mouse position report
415 The interface made assumptions
418 about the escape sequences sent to and received from the terminal.
423 library used the \fB\%get_mouse\fP capability to tell the terminal which
424 mouse button events it should send,
425 passing the mouse-button bit mask to the terminal.
426 Also, it could ask the terminal
427 where the mouse was using the \fB\%req_mouse_pos\fP capability.
429 Those features required a terminal program that had been modified
432 They were not part of the X Consortium's
440 Eric Raymond was uninterested in using the same interface due to its
441 lack of documentation.
442 Later, in 1998, Mark Hesseling provided support in
444 2.3 using the SVr4 interface.
447 does not use video terminals,
448 making it unnecessary to be concerned about compatibility with the
455 ignored in cooked mode if they have been enabled by \fB\%mousemask\fP.
459 mouse report sequence appears in the string read.
461 Mouse event reports from
463 are not detected correctly in a window with keypad application mode
465 since they are interpreted as a variety of function key.
468 capability \fB\%kmous\fP to \*(``\eE[M\*(''
469 (the beginning of the response from
472 Other values of \fB\%kmous\fP are permitted under the same assumption,
474 the report begins with that sequence.
476 Because there are no standard response sequences that serve to identify
477 terminals supporting the
481 assumes that if \fB\%kmous\fP is defined in the terminal description,
482 or if the terminal type's primary name or aliases contain the string
484 then the terminal may send mouse events.
485 The \fB\%kmous\fP capability is checked first,
486 allowing use of newer
489 such as its private mode 1006.
492 \fB\%curs_inopts\fP(3X),
493 \fB\%curs_kernel\fP(3X),
494 \fB\%curs_slk\fP(3X),
495 \fB\%curs_variables\fP(3X)