Mouse no working?

  • Anonymous - 2007-04-19

    Im using VC++ 2005 (8.0)
    I used the files in ""
    I use Windows XP Pro SP2

    The following code causes me problems:
    #include <curses.h>

    int main(int argc, _TCHAR* argv[])
        initscr();            /* Start curses mode           */
        refresh();            /* Print it on to the real screen */
        cbreak();    //Line buffering disabled. pass on everything
        int ch;
            ch = getch();
            if(ch == KEY_MOUSE)

        endwin();            /* End curses mode          */
        return 0;

    In short, nothing happens when i push any mouse button.
    I can see the screen refreshing when i press a button on the keyboard.

    Whats wrong with my code? Will it help if i build the library myself?

    • William McBrine

      William McBrine - 2007-04-19

      Since KEY_MOUSE is a "special" key, you need a call to keypad() -- "keypad(stdscr, TRUE);" -- before calling getch().

      This is kind of a nuisance -- the original purpose of setting keypad() to FALSE, in Unix curses, was to allow the special key sequences to be passed along as their component characters -- so a press of the up arrow might come through as ESC, [, A (depending on your terminal). In PDCurses, this is meaningless, and the special keys are simply filtered when keypad mode is FALSE. So I've thought about either removing this functionality, or at least setting the keypad mode to TRUE by default. But other curses implementations also start with keypad mode FALSE, so maybe it would be worse to change it; I dunno.

      Also, not on point, but argv is not a _TCHAR *; it's a char *. And personally, I'd move the "int ch;" to inside the loop.

      • Anonymous - 2007-04-19

        Many many thanks, it works like a charm now.


Log in to post a comment.