user-interfaceansi-escapeterminal-emulator

Get mouse position in pixels using escape sequences


I'm trying to obtain the position of the mouse in pixels within an application running in a terminal.

The goal is to embed small GUI elements in mostly text-based applications. It is currently possible on quite a few terminal emulators using Sixel, Tektronix or ReGIS do draw things, and \e[1000h or similar escape codes to get mouse events, unfortunately these mouse events are low-resolution (the coordinates in character cells, not in pixels).


Solution

  • xterm reports the mouse position with pixel resolution with the following escape sequences:

    Details are described at http://invisible-island.net/xterm/ctlseqs/ctlseqs.html