#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);
  term.c_lflag &= ~(ECHO | ICANON);
  tcsetattr(0, TCSANOW, &term);

  // read next mouse location
  int x,y;
  scanf("\e[<0;%d;%dM", &x, &y);

  // 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 |= ECHO | ICANON;
  tcsetattr(0, TCSANOW, &term);
}