Mouse input from PDCurses application not working #10576

Closed
opened 2026-01-31 02:24:58 +00:00 by claunia · 10 comments
Owner

Originally created by @thomthom on GitHub (Sep 10, 2020).

Environment

Windows build number: Microsoft Windows [Version 10.0.19041.450]
Windows Terminal version (if applicable): 1.2.2381.0

Any other software?
PDCurses: https://github.com/wmcbrine/PDCurses @ 618e0aa

Steps to reproduce

# CMakeLists.txt
cmake_minimum_required(VERSION 3.17)

project(CursesTest VERSION 0.1.0 LANGUAGES CXX C)

find_package(Curses REQUIRED)

set(MOUSECURSE_SOURCES
  mousecurse.cpp
)

add_executable(mousecurse ${MOUSECURSE_SOURCES})
target_link_libraries(mousecurse
  curses
)
target_compile_definitions(mousecurse PRIVATE PDC_NCMOUSE)
// mousecurse.cpp
#include <iomanip>
#include <iostream>

#include <curses.h>

void print_input(int input);

int main()
{
  initscr();
  raw();
  keypad(stdscr, TRUE);
  noecho();

  mousemask(BUTTON1_CLICKED, nullptr);

  move(1, 1);
  attron(A_BOLD);
  printw("PDCurses Mouse Test");
  attroff(A_BOLD);

  bool run = true;
  while(run) {
    refresh();
    int input = getch();

    switch(input) {
    case 'q':
      run = false;
      break;
    default:
      print_input(input);
    }
  }

  endwin();
  return 0;
}

void print_input(int input)
{
  move(3, 1);
  clrtoeol();
  printw("The pressed key is ");
  attron(A_BOLD);
  if (input & KEY_CODE_YES) {
    const char* name = keyname(input);
    printw("%i (%s)", input, name);

  } else if (input == KEY_MOUSE) {
    MEVENT event{};
    if(getmouse(&event) == OK) {
      const char* name = keyname(input);
      printw("%i (%s) [x: %i, y: %i, state: %lu]",
          input, name, event.x, event.y, event.bstate);
    }

  } else {
    printw("%i (%c)", input, input);
  }
  attroff(A_BOLD);
}

Expected behavior

I'm expecting the receive mouse input to the application. This works in normal cmd.exe:

mousecurse-cmd

Actual behavior

In Windows Terminal the mouse events doesn't reach the application, instead a text selection is made:

mousecurse-winterm

Originally created by @thomthom on GitHub (Sep 10, 2020). # Environment ```none Windows build number: Microsoft Windows [Version 10.0.19041.450] Windows Terminal version (if applicable): 1.2.2381.0 ``` Any other software? PDCurses: https://github.com/wmcbrine/PDCurses @ [618e0aa](https://github.com/wmcbrine/PDCurses/commit/618e0aaa31b4728eb4df78ec4de6c2b873908eda) # Steps to reproduce ```cmake # CMakeLists.txt cmake_minimum_required(VERSION 3.17) project(CursesTest VERSION 0.1.0 LANGUAGES CXX C) find_package(Curses REQUIRED) set(MOUSECURSE_SOURCES mousecurse.cpp ) add_executable(mousecurse ${MOUSECURSE_SOURCES}) target_link_libraries(mousecurse curses ) target_compile_definitions(mousecurse PRIVATE PDC_NCMOUSE) ``` ```cpp // mousecurse.cpp #include <iomanip> #include <iostream> #include <curses.h> void print_input(int input); int main() { initscr(); raw(); keypad(stdscr, TRUE); noecho(); mousemask(BUTTON1_CLICKED, nullptr); move(1, 1); attron(A_BOLD); printw("PDCurses Mouse Test"); attroff(A_BOLD); bool run = true; while(run) { refresh(); int input = getch(); switch(input) { case 'q': run = false; break; default: print_input(input); } } endwin(); return 0; } void print_input(int input) { move(3, 1); clrtoeol(); printw("The pressed key is "); attron(A_BOLD); if (input & KEY_CODE_YES) { const char* name = keyname(input); printw("%i (%s)", input, name); } else if (input == KEY_MOUSE) { MEVENT event{}; if(getmouse(&event) == OK) { const char* name = keyname(input); printw("%i (%s) [x: %i, y: %i, state: %lu]", input, name, event.x, event.y, event.bstate); } } else { printw("%i (%c)", input, input); } attroff(A_BOLD); } ``` # Expected behavior I'm expecting the receive mouse input to the application. This works in normal `cmd.exe`: ![mousecurse-cmd](https://user-images.githubusercontent.com/192418/92738958-b405e180-f37c-11ea-9f62-061a7ac46031.gif) # Actual behavior In Windows Terminal the mouse events doesn't reach the application, instead a text selection is made: ![mousecurse-winterm](https://user-images.githubusercontent.com/192418/92739049-c718b180-f37c-11ea-871c-0b565ac9736a.gif)
claunia added the Resolution-Duplicate label 2026-01-31 02:24:58 +00:00
Author
Owner

@jdebp commented on GitHub (Sep 10, 2020):

If it helps in diagnosis, PDCurses uses ReadConsoleInput() to read mouse input events. 48b0c12975/wincon/pdckbd.c (L575)

@jdebp commented on GitHub (Sep 10, 2020): If it helps in diagnosis, PDCurses uses `ReadConsoleInput()` to read mouse input events. https://github.com/wmcbrine/PDCurses/blob/48b0c1297529758a10a68aca0f904f90893f165d/wincon/pdckbd.c#L575
Author
Owner

@DHowett commented on GitHub (Sep 10, 2020):

So, this is a /duplicate of #376! PDCurses applications are Windows applications using the Win32 console APIs to read mouse events, and we don't currently have support in the translation layer (which is also used by ssh and other terminal emulators on Windows) for translating Win32 mouse events from VT mouse events.

@DHowett commented on GitHub (Sep 10, 2020): So, this is a /duplicate of #376! PDCurses applications are Windows applications using the Win32 console APIs to read mouse events, and we don't currently have support in the translation layer (which is also used by ssh and other terminal emulators on Windows) for translating Win32 mouse events from VT mouse events.
Author
Owner

@ghost commented on GitHub (Sep 10, 2020):

Hi! We've identified this issue as a duplicate of another one that already exists on this Issue Tracker. This specific instance is being closed in favor of tracking the concern over on the referenced thread. Thanks for your report!

@ghost commented on GitHub (Sep 10, 2020): Hi! We've identified this issue as a duplicate of another one that already exists on this Issue Tracker. This specific instance is being closed in favor of tracking the concern over on the referenced thread. Thanks for your report!
Author
Owner

@thomthom commented on GitHub (Sep 10, 2020):

Ok, I'm subscribing to the other issue. Thanks for confirming.

Are there other libraries that are currently able to achieve this in Windows Terminal? (PDCurses was the main library I found that has a working Windows implementation. ncurses seems to not support Windows.)

@thomthom commented on GitHub (Sep 10, 2020): Ok, I'm subscribing to the other issue. Thanks for confirming. Are there other libraries that are currently able to achieve this in Windows Terminal? (PDCurses was the main library I found that has a working Windows implementation. ncurses seems to not support Windows.)
Author
Owner

@DHowett commented on GitHub (Sep 10, 2020):

That's a good question. I'm not sure of that off the top of my head...
In general, anything that wants to use VT is going to be a little easier to wrangle, and be a bit more cross-platform, but was likely not originally developed for Windows. 😄

@DHowett commented on GitHub (Sep 10, 2020): That's a good question. I'm not sure of that off the top of my head... In general, anything that wants to use VT is going to be a little easier to wrangle, and be a bit more cross-platform, but was likely not originally developed for Windows. :smile:
Author
Owner

@thomthom commented on GitHub (Sep 10, 2020):

What does "VT" stand for?

@thomthom commented on GitHub (Sep 10, 2020): What does "VT" stand for?
Author
Owner

@DHowett commented on GitHub (Sep 10, 2020):

Ah, sorry. "Virtual Terminal". I typically call the in-band signalling sequences that terminals use to communicate (and applications use to communicate with terminals) "VT", though I can't determine why I do that. They do things like set color, request input mode changes ("encode these keys differently", "i want mouse input", etc.), and a whole heap of other things.

Broadly and loosely, they're the cross-platform alternative to the Win32 console APIs. Where somebody might say SetConsoleTextAttribute(FOREGROUND_RED) on Windows, they might print out the string \e[31m everywhere else.

@DHowett commented on GitHub (Sep 10, 2020): Ah, sorry. "Virtual Terminal". I typically call the in-band signalling sequences that terminals use to communicate (and applications use to communicate with terminals) "VT", though I can't determine why I do that. They do things like set color, request input mode changes ("encode these keys differently", "i want mouse input", etc.), and a whole heap of other things. Broadly and loosely, they're the cross-platform alternative to the Win32 console APIs. Where somebody might say `SetConsoleTextAttribute(FOREGROUND_RED)` on Windows, they might print out the string `\e[31m` everywhere else.
Author
Owner

@DHowett commented on GitHub (Sep 10, 2020):

(This is very broad, and very loose, but it serves to illustrate the point. jdebp could almost certainly furnish a better explanation than the one that I spent 50 seconds on 😄)

@DHowett commented on GitHub (Sep 10, 2020): (This is very broad, and very loose, but it serves to illustrate the point. jdebp could almost certainly furnish a better explanation than the one that I spent 50 seconds on :smile:)
Author
Owner

@thomthom commented on GitHub (Sep 11, 2020):

So, I could use this "Virtual Terminal" from my app to get mouse events in Windows Terminal, as a workaround until WT supports it?

If so, what APIs would I be looking at?

@thomthom commented on GitHub (Sep 11, 2020): So, I could use this "Virtual Terminal" from my app to get mouse events in Windows Terminal, as a workaround until WT supports it? If so, what APIs would I be looking at?
Author
Owner

@jdebp commented on GitHub (Sep 15, 2020):

"VT" in this context usually comes from the product names of the DEC VT range of computer terminals, the VT05 to the VT525. It stands for "video terminal", in opposition to a paper or a hardcopy terminal.

@jdebp commented on GitHub (Sep 15, 2020): "VT" in this context usually comes from the product names of the DEC VT range of computer terminals, the VT05 to the VT525. It stands for "video terminal", in opposition to a *paper* or a *hardcopy* terminal.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#10576