Mouse movement events in NCurses

假如想象 提交于 2019-11-27 23:01:23

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!