NCurses 中的鼠标移动事件 [英] Mouse movement events in NCurses
问题描述
我想知道NCurses中是否有鼠标移动事件之类的东西,是否有办法捕捉它们.遵循与鼠标交互(来自NCurses 编程 HOWTO) 似乎通过在调用中启用 REPORT_MOUSE_POSITION
位mousemask
,确实可以捕捉鼠标移动事件.
I wonder if there is such a thing as mouse movement events in NCurses, and if there is a way to catch them. Following the Interfacing with the mouse (from the NCurses programming HOWTO) it seems that by enabling the REPORT_MOUSE_POSITION
bit in the call to mousemask
, one can indeed catch mouse movement events.
所以,我试过了,但它似乎不起作用.我有这样的事情:
So, I tried that and it does not seem to work. I have something like this:
int ch, count=0;
mmask_t old;
initscr ();
noecho ();
cbreak ();
mousemask (ALL_MOUSE_EVENTS | REPORT_MOUSE_POSITION, &old);
keypad (stdscr, TRUE);
while ((ch = getchar ()) != 'q')
{
count++;
if (ch == KEY_MOUSE)
{
MEVENT event;
assert (getmouse (&event) == OK);
mvprintw (0, 0, "Mouse Event!
");
}
mvprintw (1, 1, "Event number %4d",count);
}
...
我预计当我移动鼠标光标时,我会看到事件计数器增加.但它没有.我还尝试在鼠标按钮 1 按下时移动它以查看是否生成拖动"事件,但它也没有执行任何操作.问题是,这是否只是我的终端模拟器的问题?或者我可能误解了 NCurses 认为的鼠标移动事件?接收到所有其他鼠标事件(并且我可以在使用鼠标的控制台中操作程序).
I expected that as I'll move my mouse cursor, I'll see the event counter increasing. But it didn't. I also tried moving it while mouse button 1 is down to see if generates "drag" events, and it also didn't do anything. The question is, if it's simply a problem of my terminal emulator? Or maybe I'm misunderstanding what NCurses considers as mouse movement events? All the other mouse events were received (and I can operate programs in the console that use the mouse).
我尝试了 gnome-terminal、xterm 和其他一些东西.我还通过转到我的 linux 机器(Fedora 15,Ctrl+Alt+F2)的 tty 尝试了一个文本环境(没有 X),但没有奏效.
I tried gnome-terminal, xterm, and some other stuff. I also tried a textual environment (without X) by going to the tty's of my linux machine (Fedora 15, Ctrl+Alt+F2) and that did not work.
最后,假设我做对了并且应该报告这些事件,鼠标移动事件的 MEVENT
的 bstate
字段是什么?
Finally, assuming I do get this right and those events should be reported, what is the bstate
field of a MEVENT
for a mouse movement evenet?
非常感谢!
推荐答案
您需要:
- 支持鼠标事件报告的终端;
$TERM
指向 terminfo 条目,该条目具有适当的XM
条目以正确初始化终端.
- a terminal which supports mouse event reporting;
$TERM
pointing to a terminfo entry which has an appropriateXM
entry to initialise the terminal correctly.
xterm
至少满足(1);对于 (2),您可能需要为 TERM
设置不同的值.
xterm
at least satisfies (1); for (2), it's likely that you'll need to set a different value for TERM
.
试试:
TERM=xterm-1002
在按住按钮的同时光标移动到不同的单元格时获取位置事件;或TERM=xterm-1003
每当光标移动到不同的单元格时,即使没有按下任何按钮,也始终获取位置事件.
TERM=xterm-1002
to get a position event when the cursor moves to a different cell while a button is being held down; orTERM=xterm-1003
to always get a position event whenever the cursor moves to a different cell, even if no button is pressed.
结果事件在 bstate
字段上设置了 REPORT_MOUSE_POSITION
位.
The resulting events have the REPORT_MOUSE_POSITION
bit set on the bstate
field.
(curs_mouse(3x)<的便携性"部分/code>
手册页描述了终端初始化,以及 Xterm Control Sequences 文档描述了相关的私有模式"扩展.)
(The "PORTABILITY" section of the curs_mouse(3x)
man page describes the terminal initialisation, and the "Mouse Tracking" section of the Xterm Control Sequences documentation describes the relevant "private mode" extensions.)
你上面给出的代码需要使用getch()
,而不是getchar()
;并且在循环内需要一个 refresh()
!除此之外,当使用适当的 TERM
设置之一时,它适用于 xterm
.
The code that you've given above needs to use getch()
, not getchar()
; and needs a refresh()
inside the loop! Other than that, it works for me with xterm
when using one of the appropriate TERM
settings.
这篇关于NCurses 中的鼠标移动事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!