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:
#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?
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.