.\" Automatically generated by Pandoc 2.9.2.1 .\" .TH "notcurses_input" "3" "v2.0.4" "" "" .hy .SH NAME .PP notcurses_input - input via notcurses .SH SYNOPSIS .PP \f[B]#include \f[R] .IP .nf \f[C] struct timespec; struct notcurses; typedef struct ncinput { char32_t id; // Unicode codepoint int y; // Y cell coordinate of event, -1 for undefined int x; // X cell coordinate of event, -1 for undefined bool alt; // Was Alt held during the event? bool shift; // Was Shift held during the event? bool ctrl; // Was Ctrl held during the event? uint64_t seqnum; // Monotonically increasing input event counter } ncinput; \f[R] .fi .PP \f[B]bool nckey_mouse_p(char32_t \f[R]\f[I]r\f[R]\f[B]);\f[R] .PP \f[B]char32_t notcurses_getc(struct notcurses* \f[R]\f[I]n\f[R]\f[B], const struct timespec* \f[R]\f[I]ts\f[R]\f[B], sigset_t* \f[R]\f[I]sigmask\f[R]\f[B], ncinput* \f[R]\f[I]ni\f[R]\f[B]);\f[R] .PP \f[B]char32_t notcurses_getc_nblock(struct notcurses* \f[R]\f[I]n\f[R]\f[B], ncinput* \f[R]\f[I]ni\f[R]\f[B]);\f[R] .PP \f[B]char32_t notcurses_getc_blocking(struct notcurses* \f[R]\f[I]n\f[R]\f[B], ncinput* \f[R]\f[I]ni\f[R]\f[B]);\f[R] .PP \f[B]int notcurses_mouse_enable(struct notcurses* \f[R]\f[I]n\f[R]\f[B]);\f[R] .PP \f[B]int notcurses_mouse_disable(struct notcurses* \f[R]\f[I]n\f[R]\f[B]);\f[R] .PP \f[B]int notcurses_inputready_fd(struct notcurses* \f[R]\f[I]n\f[R]\f[B]);\f[R] .PP \f[B]static inline bool ncinput_equal_p(const struct ncinput* \f[R]\f[I]n1\f[R]\f[B], const struct ncinput* \f[R]\f[I]n2\f[R]\f[B]);\f[R] .SH DESCRIPTION .PP notcurses supports input from keyboards and mice, and any device that looks like them. Mouse support requires a broker such as GPM, Wayland, or Xorg, and must be explicitly enabled via \f[B]notcurses_mouse_enable\f[R]. The full 32-bit range of Unicode is supported (see \f[B]unicode(7)\f[R]), with synthesized events mapped into the Supplementary Private Use Area-B (https://unicode.org/charts/PDF/U1.0.10.pdf). Unicode characters are returned directly as UCS-32, one codepoint at a time. .PP notcurses takes its keyboard input from \f[B]stdin\f[R], which will be placed into non-blocking mode for the duration of operation. The terminal is put into raw mode (see \f[B]cfmakeraw(3)\f[R]), and thus keys are received without line-buffering. notcurses maintains its own buffer of input characters, which it will attempt to fill whenever it reads. .PP \f[B]notcurses_getc\f[R] allows a \f[B]struct timespec\f[R] to be specified as a timeout. If \f[B]ts\f[R] is \f[B]NULL\f[R], \f[B]notcurses_getc\f[R] will block until it reads input, or is interrupted by a signal. If its values are zeroes, there will be no blocking. Otherwise, \f[B]ts\f[R] specifies a minimum time to wait for input before giving up. On timeout, 0 is returned. Signals in \f[B]sigmask\f[R] will be masked and blocked in the same manner as a call to \f[B]ppoll(2)\f[R]. \f[B]sigmask\f[R] may be \f[B]NULL\f[R]. Event details will be reported in \f[B]ni\f[R], unless \f[B]ni\f[R] is NULL. .PP \f[B]notcurses_inputready_fd\f[R] provides a file descriptor suitable for use with I/O multiplexors such as \f[B]poll(2)\f[R]. This file descriptor might or might not be the actual input file descriptor. If it readable, \f[B]notcurses_getc\f[R] can be called without the possibility of blocking. .PP \f[B]ncinput_equal_p\f[R] compares two \f[B]ncinput\f[R] structs for data equality (i.e. not considering padding or the \f[B]seqnum\f[R] field), returning \f[B]true\f[R] if they represent the same input (though not necessarily the same input event). .SS Mice .PP For mouse events, the additional fields \f[B]y\f[R] and \f[B]x\f[R] are set. These fields are not meaningful for keypress events. Mouse events can be distinguished using the \f[B]nckey_mouse_p\f[R] predicate. Once enabled, mouse button presses are detected, as are mouse motions made while a button is held down. If no button is depressed, mouse movement \f[I]does not result in events\f[R]. This is known as \[lq]button-event tracking\[rq] mode in the nomenclature of Xterm Control Sequences (https://www.xfree86.org/current/ctlseqs.html). .SS Synthesized keypresses .PP Many keys do not have a Unicode representation, let alone ASCII. Examples include the modifier keys (Alt, Meta, etc.), the \[lq]function\[rq] keys, and the arrow keys on the numeric keypad. The special keys available to the terminal are defined in the \f[B]terminfo(5)\f[R] entry, which notcurses loads on startup. Upon receiving an escape code matching a terminfo input capability, notcurses synthesizes a special value. An escape sequence must arrive in its entirety to notcurses; running out of input in the middle of an escape sequence will see it rejected. Likewise, any error while handling an escape sequence will see the lex aborted, and the sequence thus far played back as independent literal keystrokes. .PP The full list of synthesized keys (there are well over one hundred) can be found in \f[B]\f[R]. For more details, consult \f[B]terminfo(5)\f[R]. .SS \f[B]NCKEY_RESIZE\f[R] .PP Unless the \f[B]SIGWINCH\f[R] handler has been inhibited (see \f[B]notcurses_init\f[R]), notcurses will automatically catch screen resizes, and synthesize an \f[B]NCKEY_RESIZE\f[R] event. Upon receiving this event, the user may call \f[B]notcurses_refresh\f[R] to force an immediate reflow, or just wait until the next call to \f[B]notcurses_render\f[R], when notcurses will pick up the resize itself. If the \f[B]SIGWINCH\f[R] handler is inhibited, \f[B]NCKEY_RESIZE\f[R] is never generated. .SH RETURN VALUES .PP On error, the **_getc** family of functions returns \f[B](char32_t)-1\f[R]. The cause of the error may be determined using \f[B]errno(3)\f[R]. Unless the error was a temporary one (especially e.g.\ \f[B]EINTR\f[R]), \f[B]notcurses_getc\f[R] probably cannot be usefully called forthwith. On a timeout, 0 is returned. Otherwise, the UCS-32 value of a Unicode codepoint, or a synthesized event, is returned. .PP \f[B]notcurses_mouse_enable\f[R] returns 0 on success, and non-zero on failure, as does \f[B]notcurses_mouse_disable\f[R]. .PP \f[B]ncinput_equal_p\f[R] returns \f[B]true\f[R] if the two \f[B]ncinput\f[R] structs represent the same input (though not necessarily the same input event), and \f[B]false\f[R] otherwise. .SH NOTES .PP Like any other notcurses function, it is an error to call \f[B]notcurses_getc\f[R] during or after a call to \f[B]notcurses_stop\f[R]. If a thread is always sitting on blocking input, it can be tricky to guarantee that this doesn\[cq]t happen. .PP Only one thread may call into the input stack at once, but unlike almost every other function in notcurses, \f[B]notcurses_getc\f[R] and friends can be called concurrently with \f[B]notcurses_render\f[R]. .PP Do not simply \f[B]poll\f[R] the input file descriptor. Instead, use the file descriptor returned by \f[B]notcurses_inputready_fd\f[R] to ensure compatibility with future versions of Notcurses (it is possible that future versions will process input in their own contexts). .SH BUGS .PP Failed escape sequences are not yet played back in their entirety; only an ESC (ASCII 0x1b) will be seen by the application. .PP The Shift key is only indicated in conjunction with mouse button presses. If e.g.\ Shift is used to generate a capital letter `A', \f[B]id\f[R] will equal `A', and \f[B]shift\f[R] will be \f[B]false\f[R]. This should be fixed in the future. .PP When Ctrl is pressed along with a letter, the letter will currently always be reported in its uppercase form. E.g., if Shift, Ctrl, and `a' are all pressed, this is indistinguishable from Ctrl and `a' without Shift. This should be fixed in the future. .PP Ctrl pressed along with `J' or `M', whether Shift is pressed or not, currently registers as \f[B]NCKEY_ENTER\f[R]. This will likely change in the future. .SH SEE ALSO .PP \f[B]poll(2)\f[R], \f[B]cfmakeraw(3)\f[R], \f[B]notcurses(3)\f[R], \f[B]notcurses_refresh(3)\f[R], \f[B]notcurses_render(3)\f[R], \f[B]termios(3)\f[R], \f[B]terminfo(5)\f[R], \f[B]ascii(7)\f[R], \f[B]signal(7)\f[R], \f[B]unicode(7)\f[R] .SH AUTHORS nick black .