NCurses 中的鼠标移动事件

发布于 2024-12-04 23:24:21 字数 1155 浏览 1 评论 0原文

我想知道NCurses中是否有鼠标移动事件之类的东西,以及是否有办法捕获它们。遵循与鼠标交互(来自NCurses 编程 HOWTO)似乎通过启用调用mousemask 中的REPORT_MOUSE_POSITION 位,确实可以捕获鼠标移动事件。

所以,我尝试了一下,但似乎不起作用。我有这样的事情:

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 认为的鼠标移动事件?所有其他鼠标事件均已收到(并且我可以在控制台中操作使用鼠标的程序)。

我尝试了 gnome-terminal、xterm 和其他一些东西。我还通过进入我的 linux 机器(Fedora 15,Ctrl+Alt+F2)的 tty 尝试了文本环境(没有 X),但这不起作用。

最后,假设我确实做到了这一点并且应该报告这些事件,那么鼠标移动事件的 MEVENTbstate 字段是什么?

非常感谢!

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

...

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).

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.

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?

Many thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

℉絮湮 2024-12-11 23:24:21

您需要:

  1. 一个支持鼠标事件上报的终端;
  2. $TERM 指向 terminfo 条目,该条目具有适当的 XM 条目以正确初始化终端。

xterm 至少满足 (1);对于 (2),您可能需要为 TERM 设置不同的值。

尝试:

  • TERM=xterm-1002 获取当按住按钮时光标移动到不同单元格时的位置事件;或
  • TERM=xterm-1003,只要光标移动到不同的单元格,即使没有按下任何按钮,也始终会获取位置事件。

生成的事件在 bstate 字段上设置了 REPORT_MOUSE_POSITION 位。

curs_mouse(3x) 的“便携性”部分 手册页描述了终端初始化,以及 的“鼠标跟踪”部分 扩展。)

href="http://invisible-island.net/xterm/ctlseqs/ctlseqs.html" rel="noreferrer">Xterm 控制序列文档描述了相关的“私有模式” 上面给出的需要使用 getch(),而不是 getchar();并且需要在循环内使用 refresh()!除此之外,当使用适当的TERM设置之一时,它对我来说适用于xterm

You need:

  1. a terminal which supports mouse event reporting;
  2. $TERM pointing to a terminfo entry which has an appropriate XM entry to initialise the terminal correctly.

xterm at least satisfies (1); for (2), it's likely that you'll need to set a different value for TERM.

Try:

  • TERM=xterm-1002 to get a position event when the cursor moves to a different cell while a button is being held down; or
  • TERM=xterm-1003 to always get a position event whenever the cursor moves to a different cell, even if no button is pressed.

The resulting events have the REPORT_MOUSE_POSITION bit set on the bstate field.

(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.)

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文