blob: c7d3e57b68fd8b4bd47102e4d10f990b8215d201 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
// Test the ncurses mouse API
//gcc -o mouse-test mouse-test.c -I~/working-copies/ncurses-snapshots/include ~/working-copies/ncurses-snapshots/lib/libncursesw.a
#include <strings.h>
#include <curses.h>
#include <term.h>
#define BUTTON_NUM(X) \
(BUTTON##X##_PRESSED | BUTTON##X##_RELEASED | \
BUTTON##X##_CLICKED | BUTTON##X##_DOUBLE_CLICKED | BUTTON##X##_TRIPLE_CLICKED)
#define BUTTON_EVENT(X) \
(BUTTON1_##X | BUTTON2_##X | BUTTON3_##X | BUTTON4_##X | BUTTON5_##X)
int main(void)
{
initscr();
raw();
noecho();
scrollok(stdscr, TRUE);
keypad(stdscr, TRUE);
mouseinterval(0);
mousemask(BUTTON_EVENT(PRESSED) | BUTTON_EVENT(RELEASED) /*| REPORT_MOUSE_POSITION*/, NULL);
// mousemask(ALL_MOUSE_EVENTS, NULL);
for (;;) {
MEVENT event;
int c = wgetch(stdscr);
if (c == '\e')
break;
if (c != KEY_MOUSE)
continue;
while (getmouse(&event) == OK) {
printw("EVENT: 0x%016X == %02d [%c%c%c%c%c%c]\n",
event.bstate, ffs(event.bstate)-1,
event.bstate & BUTTON_NUM(4) ? 'U' : ' ',
event.bstate & BUTTON_NUM(5) ? 'D' : ' ',
event.bstate & BUTTON_EVENT(PRESSED) ? 'P' : ' ',
event.bstate & BUTTON_EVENT(RELEASED) ? 'R' : ' ',
event.bstate & BUTTON_EVENT(CLICKED) ? 'C' : ' ',
event.bstate & REPORT_MOUSE_POSITION ? 'M' : ' ');
}
}
endwin();
return 0;
}
|