简体   繁体   English

ncurses 检测鼠标何时离开窗口

[英]ncurses detect when mouse leaves window

When I research mouse interfacing with ncurses, I see many options, but I do not see any way to detect when the mouse has left the program window.当我研究鼠标与 ncurses 的接口时,我看到了很多选项,但我没有看到任何方法来检测鼠标何时离开程序窗口。 The window is the window of the terminal emulator, not an ncurses window.该窗口是终端仿真器的窗口,而不是 ncurses 窗口。

That's not in the repertoire of ncurses' mouse interface, but for some terminals you could set them up to send xterm's leave- and enter-window control sequences, which your program could read either byte-by-byte using getch , or by using define_key to associate the responses as a "function key".这不是在剧目的ncurses'鼠标接口,但对于一些终端,你可以将其设置为发送的xterm的免洗型和输入窗口控制序列,你的程序可以使用读取这两种逐字节getch ,或使用define_key将响应关联为“功能键”。

XTerm Control Sequences lists in the section on FocusIn/FocusOut : FocusIn/FocusOut部分中的XTerm Control Sequences列表:

FocusIn/FocusOut can be combined with any of the mouse events since it uses a different protocol. FocusIn/FocusOut 可以与任何鼠标事件结合使用,因为它使用不同的协议。 When set, it causes xterm to send CSI I when the terminal gains focus, and CSI O when it loses focus.设置后,它会导致 xterm 在终端获得焦点时发送CSI I ,而在失去焦点时发送CSI O

That is enabled with这是启用的

CSI ? Pm h
          DEC Private Mode Set (DECSET).
...
            Ps = 1 0 0 4  -> Send FocusIn/FocusOut events, xterm.

for instance,例如,

printf("\033[?1004h");
fflush(stdout);

(a few other terminals implement this, but since they do not document their behavior, you'll have to experiment to find out whether this applies to the terminal you happen to be using). (其他一些终端实现了这一点,但由于它们没有记录它们的行为,您必须进行试验以确定这是否适用于您碰巧使用的终端)。

In ncurses, you could associate the responses with define_key , eg,在 ncurses 中,您可以将响应与define_key相关联,例如,

#define KEY_FOCUS_IN     1001
#define KEY_FOCUS_OUT    1002

define_key("\033[I", KEY_FOCUS_IN);
define_key("\033[O", KEY_FOCUS_OUT);

and (if keypad is enabled), detect those values in your program as the return value from getch .并且(如果启用了keypad ),将程序中的这些值检测为getch的返回值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM