【发布时间】:2013-05-22 14:40:10
【问题描述】:
我正在使用 ncurses 编写用户界面。 当我的终端宽度或高度超过 222 个字符/行时,我遇到问题,鼠标坐标返回 -33 值,所以当我点击超过 222 个字符时 mouse_x = -33 当我点击超过 222 行 mouse_y = -33
是否可以告诉 ncurses 不停止超过 222 个字符/行的鼠标事件? 这个错误也出现在 vim 中,当您将 :vs 分隔条移动到 222 个字符之外时,它会回到 x=0。
也许这个错误已经修复了?
1 #include <ncurses.h>
2
3 void treat_mouse(MEVENT* event);
4
5 int main(void)
6 {
7 bool run;
8 int key;
9 MEVENT event;
10
11 run = true;
12 initscr();
13 noecho();
14 keypad(stdscr, TRUE);
15 mousemask(BUTTON1_PRESSED, NULL);
16 while (run == true)
17 {
18 key = getch();
19 switch (key)
20 {
21 case 'q':
22 run = false;
23 break;
24 case KEY_MOUSE:
25 treat_mouse(&event);
26 break;
27 default:
28 break;
29 }
30 }
31 endwin();
32 return 0;
33 }
34
35 void treat_mouse(MEVENT* event)
36 {
37 if (getmouse(event) == OK)
38 mvwprintw(stdscr, 0, 0, "click: x = %d, y = %d\n", event->x, event->y);
39 }
.
.
=========================编辑====================== =
.
.
好的,我找到了。
我在这里下载了ncurses代码源http://ftp.gnu.org/pub/gnu/ncurses/
我已使用此链接 ncurses-5.9.tar.gz 04-Apr-2011 19:12 2.7M
我已经搜索过 getch()。
getch() 调用 wgetch()。
wgetch() 调用 _nc_wgetch()。
_nc_wgetch() 调用 _mouse_inline()。
_mouse_inline() 是 struct screen 中调用 _nc_mouse_inline() 或 no_mouse_inline() 的函数指针谁是一个空函数(我认为没有鼠标时)。
您可以在 ncurses-5.9/ncurses/base/lib_mouse.c
中看到 _nc_mouse_inline() 函数她使用 unsigned char 来计算鼠标坐标,看看这个小例子:
821 static bool
822 _nc_mouse_inline(SCREEN *sp)
823 /* mouse report received in the keyboard stream -- parse its info */
824 {
.
.
.
832 unsigned char kbuf[4];
.
.
.
970 eventp->x = (kbuf[1] - ' ') - 1;
971 eventp->y = (kbuf[2] - ' ') - 1;
.
.
.
984 return (result);
985 }
最后我会做任何事情。
【问题讨论】:
标签: c events mouse ncurses curses