Mouse movement events in NCurses

前端 未结 1 1099
抹茶落季
抹茶落季 2020-12-06 06:22

I wonder if there is such a thing as mouse movement events in NCurses, and if there is a way to catch them. Following the Interfacing with the mouse (from the NCurses progra

相关标签:
1条回答
  • 2020-12-06 06:34

    You need:

    1. a terminal which supports mouse event reporting;
    2. $TERM pointing to a terminfo entry which has an appropriate XM entry to initialise the terminal correctly.

    xterm at least satisfies (1); for (2), it's likely that you'll need to set a different value for TERM.

    Try:

    • TERM=xterm-1002 to get a position event when the cursor moves to a different cell while a button is being held down; or
    • TERM=xterm-1003 to always get a position event whenever the cursor moves to a different cell, even if no button is pressed.

    The resulting events have the REPORT_MOUSE_POSITION bit set on the bstate field.

    (The "PORTABILITY" section of the curs_mouse(3x) man page describes the terminal initialisation, and the "Mouse Tracking" section of the Xterm Control Sequences documentation describes the relevant "private mode" extensions.)

    The code that you've given above needs to use getch(), not getchar(); and needs a refresh() inside the loop! Other than that, it works for me with xterm when using one of the appropriate TERM settings.

    0 讨论(0)
提交回复
热议问题