Open jquast opened 10 years ago
Is there still no way to track mouse events? I tried manually enabling mouse tracking with escape sequences and parsing the sequences that inkey() returns. It works fine until I click on a spot where the x or y coordinate is bigger than 127, and that makes blessed throw an exception, because the getch() method tries to decode the bytes representing the coordinates as unicode, and fails.
I really want to be able to track mouse events from my application, so if someone could tell me a way to do it, I would be very grateful.
It is possible — I’m sorry I can’t help write any code for some time, I’m a bit busy this holiday, but I referenced all of the code that could be stitched together into a PR and I would be happy to accept any good one with tests and docs!
Best wishes, hope you are working on something fun
this was already done once before in a rejected blessings patch last year,
https://asciinema.org/a/2871 <- scroll wheel https://asciinema.org/a/2866 <- click detection
https://gist.github.com/jquast/7018509#file-__init__-py-L511-L536
Not so sure about the given solution, I need to be persuaded about the context manager names and possible keyword argument/values.
Furthermore, the "Keystroke" class type returned by Terminal.inkey() can now return MouseEvent as well -- they now need to derive from the same base class, providing the same .code and .is_sequence() methods. I think I would further like attribute "kind" of values "MouseEvent" or "keystroke".
Mouse input provides (x,y) attributes, but even bounding box attributes etc., a class needs to be made to support all such decoding, example of decoding and game is done here ("drawing boxes" demo)
https://gist.github.com/jquast/7018509#file-test_mouse-py-L259-L356