在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!\n");
}
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中,和一些其他的东西。我也要去TTY我的Linux机器的公司(Fedora的15,按Ctrl + Alt + F2)尝试文本环境(不带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 $ C $的
bstate
字段C>的鼠标移动evenet?
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
指向其中有一个相应的XM
进入正确初始化终端的terminfo项。
- 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
来始终获得位置的事件,只要将光标移动到不同的细胞,即使没有按钮是pressed。
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.
产生的事件具有 REPORT_MOUSE_POSITION
位置上的 bstate
字段。
The resulting events have the REPORT_MOUSE_POSITION
bit set on the bstate
field.
(将便携性的 的curs_mouse节(3次)
手册页介绍了终端初始化和的Xterm控制的鼠标跟踪部分序列文档描述了相关的私密模式扩展名)。
(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.)
这是你上面给出的code需要使用残培()
,而不是的getchar()
;并且需要刷新()
循环里面!除此之外,它为我的作品与的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屋!