Using ncurses to capture mouse clicks on a console application
The right mouse button is button 3, not button 2. Button 2 is the middle one.
For anyone else coming here trying to figure out why s/he can't capture mouse events at all with Ncurses, most likely this is the line that you need:
keypad(window, TRUE);
Without this, I didn't get any mouse events with getch()
.
It's missing from all the tutorials/examples I've seen, that's why it took me a lot of time to figure out what was wrong with my code - maybe this answer will help others find the solution faster than I did.
The original question was about terminal emulators (and menu activation interfering with passing mouse-clicks to an application). That could have been addressed by some terminal-specific documentation (or even some tutorial). Other answers missed that point, and focused on problems in an ncurses application receiving (and making sense of) the xterm protocol mouse-events.
The latter issue is documented in the manual page:
Mouse events under
xterm
will not be detected correctly in a window with itskeypad
bit off, since they are interpreted as a variety of function key. Your terminfo description should havekmous
set to"\E[M"
(the beginning of the response from xterm for mouse clicks). Other values forkmous
are permitted, but under the same assumption, i.e., it is the beginning of the response.
not new, first mentioned in 1995:
Mouse events under xterm will not be detected correctly in a window with its keypad bit off.