You are not logged in.
I'm trying to write some software with ncurses, but mouse events are always reported as bad. I'm using xterm. Do I need to install something beyond ncurses? Here's some sample code that I'm using:
#include <ncurses.h>
#include <assert.h>
int main() {
int ch, count=0;
mmask_t old;
initscr ();
clear();
noecho ();
cbreak ();
keypad (stdscr, TRUE);
mousemask (ALL_MOUSE_EVENTS | REPORT_MOUSE_POSITION, &old);
while ((ch = getch ()) != '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);
refresh();
}
}
A number of events are reported when I click, but they're not mouse events. In addition, has_mouse() always returns false.
Last edited by euclio (2015-07-20 19:38:07)
Offline
I think you should use getch() instead of getchar()
while ((ch = getch()) != 'q')
For some examples, see also http://tldp.org/HOWTO/NCURSES-Programmi … TINGEVENTS
Last edited by mauritiusdadd (2015-07-19 22:51:50)
Offline
You're right, but I'm still having the same issues. Edited OP.
Last edited by euclio (2015-07-20 03:25:20)
Offline
Strange, it works fine for me... What command are you using to compile the program? Can you test the following code and paste here the output after a mouse click?
#include <ncurses.h>
#include <assert.h>
int main() {
int ch, count=0;
MEVENT event;
initscr();
raw();
keypad(stdscr, TRUE);
noecho();
clear();
cbreak();
mousemask(ALL_MOUSE_EVENTS | REPORT_MOUSE_POSITION, NULL);
while ((ch = getch()) != 'q')
{
count++;
mvprintw(1, 1, "Has mouse: %d", has_mouse());
mvprintw(2, 1, "Key code: %x; mouse code:%x", ch, KEY_MOUSE);
if (ch == KEY_MOUSE)
{
assert(getmouse(&event) == OK);
mvprintw(3, 3, "Mouse Event: x=%d, y=%d z=%d",
event.x, event.y, event.z);
mvprintw(4, 3, "Mouse device id: %x", event.id);
mvprintw(5, 3, "Mouse button mask: %x", event.bstate);
}
mvprintw(6, 1, "Event number: %4d",count);
refresh();
}
endwin();
}
Also, are you using a mouse or a touchpad? Does it work if you click while pressing the Alt or Meta/Super key? Can you post the output of the following commands?
uname -a
pacman -Qi ncurses
--edit: fixed a typo (missing parenthesis)
Last edited by mauritiusdadd (2015-07-20 11:15:58)
Offline
It also works fine for me. I tried first in tmux within urxvt, then to ensure it wasn't a terminal issue I installed and tested in xterm and it worked fine - even when I set a couple bad 'TERM' values.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Huh. Your example now works flawlessly, as well as my original example. I must have missed something. Thank you for your help.
Offline