Skip to content

GetMouse does not work for reporting mouse position #16

@ppebb

Description

@ppebb

This functionality works fine in C, but when using dotnet curses you do not get the proper position of the mouse, it is all 0, 0. If you check the actual return value of GetMouse it is -1.

Both this and this (if you add a printf for the escape code) give the correct position.

public class Program
{
        [DllImport("libc", SetLastError = true, CharSet = CharSet.Unicode)]
        private static extern void setlocale(int category, string locale);

        private const int LC_ALL = 6;

        public static void Main()
        {
                setlocale(LC_ALL, "");
                nint std = NCurses.InitScreen();
                NCurses.CBreak();
                NCurses.NoEcho();
                NCurses.SetCursor(0);
                NCurses.HalfDelay(1);
                NCurses.Keypad(std, true);
                NCurses.MouseMask(CursesMouseEvent.ALL_MOUSE_EVENTS | CursesMouseEvent.REPORT_MOUSE_POSITION, out _);
                Console.WriteLine("\x1b[?1003h");

                while (true)
                {
                        string ret;
                        int c;
                        try
                        {
                                c = NCurses.WindowGetChar(std);
                        }
                        catch
                        {
                                continue;
                        }

                        if (c == '\r' || c == '\n')
                                break;

                        if (c == -1)
                                ret = "nothing happened";
                        else if (c == CursesKey.MOUSE)
                        {
                                try
                                {
                                        NCurses.GetMouse(out MouseEvent e);
                                        ret = $"mouse event {e.x} {e.y} {e.bstate}";
                                }
                                catch
                                {
                                        ret = "bad mouse event";
                                }
                        }
                        else
                                ret = $"key {c} pressed";

                        NCurses.Move(0, 0);
                        NCurses.InsertLine();
                        NCurses.AddString(ret);
                        NCurses.ClearToEndOfLine();
                        NCurses.Move(0, 0);
                }

                NCurses.EndWin();
        }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions