1

I'm writing a terminal program on the Kindle Paperwhite 2. I compile using tcc. I use linux. I want to implement functions such as gotoxy(x,y) and the Mouse. To move the cursor, I need to send control codes. I found I use printf like this:

printf("\033[%d;%dH",y,x);

The problem is how to receive control codes sent back to me from the terminal. I'm reading this document

I wrote the following code:

printf("\033[?9h");//this turns on the mouse in the terminal
while (1)
{
    printf("\n");
    sleep(1);
}

Using scanf or getch() doesn't capture anything. Now every time I click, I see a code on the screen (like "^[[M 9.").
It's as if the code doesn't get printed unless a newline is printer. I need to be able to capture the last two characters as decimals which i think is the xy of the screen.
Can someone help?
Thanks

Aryeh Beitz
  • 1,974
  • 1
  • 22
  • 23

1 Answers1

0

First of all, I highly recommend not dealing with the escape sequences. Use ncurses.

Now keep in mind that

Because the console driver has no way to know the device or type of the mouse, these reports are returned in the console input stream only when the virtual terminal driver receives a mouse update ioctl.

user58697
  • 7,808
  • 1
  • 14
  • 28