You are not logged in.

#1 2022-09-09 19:53:41

njstaticuser
Member
Registered: 2022-09-09
Posts: 6

[SOLVED]NCurses doesn't seem to recognize mouse events

This is my first post so I apologize if I do thhings wrong here! I am making an ncurses program with mouse support. A few days ago the support for the mouse event KEY_MOUSE no longer works. The

'getmouse(&event) == OK);'

always returns false now.  I am unsure how mouse support stopped working. Here is a list of things I have tried:

- Changed my TERM variable to try the program in different terminal emulators including xterm, xterm-256color, vte-256color, and others that has mouse support.
- Compiled a termcap source from https://invisible-island.net/ncurses/terminfo.src.html into a new ~/.terminfo. Changed the path of TERMINFO to only choose this path.
- Downgraded arch to a version during a time I knew the program works
- Checked this forum for solutions

Here is my source code:

#include <stdlib.h>
#include <stdio.h>
#include <ncurses.h>
#include <assert.h>

int main(void);
int main()
{
	int c = 0;
	MEVENT e;

  if(initscr() == NULL)
    return -5;

	raw();
	noecho();
  keypad(stdscr, TRUE);
  curs_set(0);

	printf("\033[?1003h\n");
	fflush(stdout);
	mousemask(ALL_MOUSE_EVENTS | REPORT_MOUSE_POSITION, NULL);

	do
	{
		c = getch();
		if (c == KEY_MOUSE)
			printf("mouse was pressed\n");
	
	}while(c != '\n');

	printf("\033[?1003l\n");
	clear();
	endwin();
	return 0;
}

The terminal recognizes mouse events (I get a bunch of gibberish when I move the mouse or click it). But I cannot get past the KEY_MOUSE conditional statement. This program worked in the past now it does not. I hope someone can offer a solution! Thank you very much for your time!

Last edited by njstaticuser (2022-09-10 03:46:25)

Offline

#2 2022-09-09 20:04:56

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 27,272
Website

Re: [SOLVED]NCurses doesn't seem to recognize mouse events

That code works fine here, how - exactly - are you compiling it?

njstaticuser wrote:

The terminal recognizes mouse events (I get a bunch of gibberish when I move the mouse or click it).

Can you give an example of this "gibberish"?

njstaticuser wrote:

But I cannot get past the KEY_MOUSE conditional statement.

Then check what 'c' actually is as well as checking the value at that point of 'KEY_MOUSE' (i.e., print them to the screen or a log).

But what does any of this have to do with the note about "getmouse(&event) == OK" ... that doesn't appear at all in your code sample.

Last edited by Trilby (2022-09-09 20:05:42)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#3 2022-09-09 20:30:45

njstaticuser
Member
Registered: 2022-09-09
Posts: 6

Re: [SOLVED]NCurses doesn't seem to recognize mouse events

The value of 'c' is 279177328944 when I left-clicked my mouse
The gibberish output is:

^[[?1049h^[[22;0;0t^[[1;38r^[(B^[[m^[[4l^[[?7h^[[?1h^[=^[[?25l^[[?1003h
^[[?1000h^[[H^[[2J^[[?1000l^[[38;1H^[[?12l^[[?25h^[[?1049l^[[23;0;0t^M^[[?1l^[>10
^[[?1003l

I do not need to use the getmouse() function since I cannot even get past KEY_MOUSE condition (which the value is 409). But I have added it in the past and the condition always fail.

I have compiled the code as follows: gcc -ggdb -o test mouse_events.c -lncurses

I hope that helps!

Last edited by njstaticuser (2022-09-09 20:33:04)

Offline

#4 2022-09-09 21:12:11

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 27,272
Website

Re: [SOLVED]NCurses doesn't seem to recognize mouse events

njstaticuser wrote:

The value of 'c' is 279177328944 when I left-clicked my mouse

Given that 'c' is declared as 'int' and that value is greater than INT_MAX, I gather there was an error in how you checked the value.  Did you print it?  If so, how?


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#5 2022-09-09 21:25:19

njstaticuser
Member
Registered: 2022-09-09
Posts: 6

Re: [SOLVED]NCurses doesn't seem to recognize mouse events

Trilby wrote:

Given that 'c' is declared as 'int' and that value is greater than INT_MAX, I gather there was an error in how you checked the value.  Did you print it?  If so, how?

I used the standard printf() function I outputted the data like this:
./test >> moutput.log

I clicked once on the screen. I took the output (onto stdout I assume) and removed the enter character (to exit the program. It had a value of 10), and the mouse button going back up character (similar if not
exactly the value).

The gibberish comes from the output stored in that log. I opened it up using nano on a terminal and copied the data and pasted it here. I did notice that the value of c exceeds the capabilities of an int type, but I run a 64-bit architecture and OS. That value should be within the range of a long int maybe? But I didn't specify a long int. That is a bit odd. But as you can see in my program I am using a standard form of comparison. I am not sure what else I can do.

Offline

#6 2022-09-09 21:35:42

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 27,272
Website

Re: [SOLVED]NCurses doesn't seem to recognize mouse events

njstaticuser wrote:

I used the standard printf() function

Can you show the exact code?


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#7 2022-09-09 21:38:29

njstaticuser
Member
Registered: 2022-09-09
Posts: 6

Re: [SOLVED]NCurses doesn't seem to recognize mouse events

Ok here it is!

#include <stdlib.h>
#include <stdio.h>
#include <ncurses.h>
#include <assert.h>

int main(void);

int main()
{
	int c = 0;
	MEVENT e;

  if(initscr() == NULL)
    return -5;

	raw();
	noecho();
  cbreak();
  keypad(stdscr, TRUE);
  curs_set(0);

	mousemask(ALL_MOUSE_EVENTS | REPORT_MOUSE_POSITION, NULL);

	do
	{
		c = getch();
    printf("%d", c);
		if (c == KEY_MOUSE)
			printf("mouse was pressed\n");
	
	}while(c != '\n');

	clear();
	endwin();
	return 0;
} 

Offline

#8 2022-09-09 23:06:29

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 27,272
Website

Re: [SOLVED]NCurses doesn't seem to recognize mouse events

Thanks - that looks good (I wanted to rule out misuses of printf that might produce unexpected results).  I'd personally add a newline or other separator for the number to ensure multiple "c" values weren't running together - but the result you get in your log doesn't even include a 409, so there getch is indeed returning something else (I'm still puzzled by it being more than INT_MAX, but now I highly doubt that is relevant).

The only other thought I'd have is if there was stray input signal coming from somewhere else (a bad keyboard wire, ect), but this would certainly show symptoms in other contexts outside of your program.  So sorry, not much help here, but I can confirm your code is good and should work.  Can you confirm that your system is up to date and nothing is off with the ncurses package (check pacman -Qkk ncurses).

Last edited by Trilby (2022-09-10 02:34:17)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#9 2022-09-10 00:18:26

njstaticuser
Member
Registered: 2022-09-09
Posts: 6

Re: [SOLVED]NCurses doesn't seem to recognize mouse events

Here is some output of the info you requested:

[test@darkclam ~]$ pacman -Qkk ncurses
ncurses: 3857 total files, 0 altered files
[test@darkclam ~]$ uname -r
5.18.12-arch1-1
[test@darkclam ~]$ 

Trilby you have been awesome! I do appreciate your input. Does this program work for you when you compile it? Also I downgraded my OS to see if the recent update was the issue. I have ncurses version 6.3-3

Offline

#10 2022-09-10 00:32:21

njstaticuser
Member
Registered: 2022-09-09
Posts: 6

Re: [SOLVED]NCurses doesn't seem to recognize mouse events

I solved it! It was a corrupted terminfo. I deleted the corrupted data and pointed it to a fresh terminfo! Thank you for your input!

Offline

#11 2022-09-10 02:33:51

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 27,272
Website

Re: [SOLVED]NCurses doesn't seem to recognize mouse events

Glad you sorted it out.  Please mark the thread as [solved by clicking "edit" on your first post to prepend [SOLVED] to the title.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

Board footer

Powered by FluxBB