#include <termios.h>
#include <stdio.h>
int main()
{
// one way to enable mouse tracking
printf("\e[?1000h\e[?1006h");
// disable echo and line buffering for mouse
struct termios term;
tcgetattr(0, &term);
int user_lflag = term.c_lflag;
term.c_lflag &= ~(ECHO | ICANON);
tcsetattr(0, TCSANOW, &term);
// read next mouse location
int w,x,y;
char b;
scanf("\e[<%d;%d;%d%c", &w, &x, &y, &b);
// disable mouse tracking, maybe misordered
printf("\e[?1000l");
// output mouse location
printf("%d %d\n", x, y);
// enable echo and line buffering
term.c_lflag |= user_lflag;
tcsetattr(0, TCSANOW, &term);
}