Not able to get current cursor position

Sep 11, 2021 at 11:51am
I'm using ncurses.h to make a simple GUI to my C++ project. I'm just trying to get cursor position when the user click with mouse but I always get the same output (0,0), here's the code:
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
#include <ncurses.h>
#include <iostream>

int main(){

int x, y;
char c;

initscr();
clear();
noecho();
mousemask(ALL_MOUSE_EVENTS,NULL);

while(1){
 c = getch();
 if ( c == BUTTON1_CLICKED ) {
   getyx(stdscr,x,y);
   printw("POS(%d,%d)\n",x,y);
   refresh();

     }

 }
return 0;
}


The program don't print anything until I click with mouse on terminal, but the coordinates are always the same (0,0), even if cursor positon change. Does someone know how can I solve this?
Last edited on Sep 11, 2021 at 11:52am
Sep 11, 2021 at 1:42pm
getxy() gets the cursor position. The "cursor" refers to the caret, which is where the next character is going to be inserted. Clicking the mouse doesn't change this variable.

https://tldp.org/HOWTO/NCURSES-Programming-HOWTO/mouse.html
Sep 11, 2021 at 1:50pm
Topic archived. No new replies allowed.