views:

30

answers:

1

I'm trying to find a way to get mouse click event in curse module in Python.

I read the document on http://docs.python.org/library/curses.html and it suggested to do

c == curses.getch()
if(c == curses.KEY_MOUSE):
    curses.getmouse()
    ...

However, this "if statement" seems to never get triggered... and if I tried to move the getmouse() function outside of "if statement" to force it to return the mouse information, it return

    (devid,x,y,z,bstate) = curses.getmouse()
_curses.error: getmouse() returned ERR

Any other thought?

+3  A: 

Have you enabled mouse-event reporting with the mousemask function, and checked its return value to make sure it confirms that it can actually report some mouse-events? Depending on the terminal (or emulator program for one, these days;-), mouse event reporting may or may not be possible, in whole or in part; and in any case, it's disabled by default in curses (not just on Python, that's a curses general idea;-) unless and until you explicitly enable it with the mousemask call.

Alex Martelli
After I enable the mousemask function, it works as I expected. Thanks for your prompt reply.
Patrick
@Patrick, you're welcome - glad to have been of help!
Alex Martelli