gpt4 book ai didi

c++ - ncurses 检测鼠标何时离开窗口

转载 作者:太空狗 更新时间:2023-10-29 12:09:06 25 4
gpt4 key购买 nike

当我研究鼠标与 ncurses 的接口(interface)时,我看到了很多选项,但我没有看到任何方法来检测鼠标何时离开程序窗口。窗口是终端模拟器的窗口,不是ncurses窗口。

最佳答案

这不在 repertoire 中ncurses 的鼠标界面,但对于某些终端,您可以将它们设置为发送 xterm 的离开和进入窗口控制序列,您的程序可以使用 getch 逐字节读取,或者通过使用 define_key 将响应关联为“功能键”。

XTerm Control Sequences FocusIn/FocusOut 部分列出:

FocusIn/FocusOut can be combined with any of the mouse events since it uses a different protocol. When set, it causes xterm to send CSI I when the terminal gains focus, and CSI O when it loses focus.

启用

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

例如,

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

(一些其他终端实现了这一点,但由于它们没有记录它们的行为,因此您必须进行试验以确定这是否适用于您碰巧正在使用的终端)。

在 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);

并且(如果启用了keypad),检测程序中的这些值作为getch 的返回值。

关于c++ - ncurses 检测鼠标何时离开窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54472426/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com