Curses has a very low level API - back to 1980's C'programing.
Python shells have higher-level support for keyboard input and some other subtleties, but they are few in number and separate and not very well documented.
The intricacies of Python do not include mouse support (well, you return your mouse state to the tuple, instead of creating a C structure for it, so it's a little better).
The idea is to turn on the curses window, turn on the "keyboard" so that Python gives you full key codes, turn on "mousemask" so that mouse events are sent to your application. Detection of the special mouse_key keyboard code in the getch function so that you can call getmouse to get the coordinates and state of the button.
Thus, there are no ready-made good callbacks, you must configure the mainloop of your application to detect mouse events yourself.
This code example follows the steps above to read mouse events and print the state of the mouse on the screen โ this should be enough to get started creating useful mouse processing using curses:
# -*- coding: utf-8 -*- import curses screen = curses.initscr() curses.noecho() curses.mousemask(curses.ALL_MOUSE_EVENTS) screen.keypad(1) char = "" try: while True: char = screen.getch() screen.addstr( str(char) + " ") if char == curses.KEY_MOUSE: screen.addstr (" |" + str(curses.getmouse()) + "| ") finally: screen.keypad(0) curses.endwin() curses.echo()
source share