nsf / termbox

Library for writing text-based user interfaces
http://code.google.com/p/termbox
MIT License
1.97k stars 187 forks source link

Keyboard input corrupted when scrolling in python on a macintosh #78

Open dj-on-github opened 8 years ago

dj-on-github commented 8 years ago

scrolltest.txt I found my termbox based program was quitting when scrolling with the touchpad on a macbook. I traced this to the program receiving ESCs while scrolling, when it should only be getting arrow up or down events.

I wrote a test case that gets counts the events. Run it, scroll up a few times, then press X to quit and print the results. Without a time delay in the loop, this works fine. You only get up arrow events. I added a time delay in the loop to simulate the delay in updating the view in my program. Then 3 other different events are received, including ESC.

Without delay.. $ ./scrolltest.py (1, None, 65516, 0, 0, 0, 0, 0) : 14

With delay.. ./scrolltest.py (1, u'O', 0, 0, 0, 0, 0, 0) : 1 (1, u'B', 0, 0, 0, 0, 0, 0) : 1 (1, None, 65516, 0, 0, 0, 0, 0) : 104 (1, None, 27, 0, 0, 0, 0, 0) : 1

So something is up with the event handling. It seems to be chopping up the escape sequences into smaller chunks before they are interpreted as key strokes.

scrolltest.py...

nsf commented 8 years ago

Yeah, sadly it's a known fact on osx: https://github.com/nsf/termbox-go/issues/132. Not sure what to do about it.

rationull commented 6 years ago

The linked termbox-go issue was resolved by adding a short wait when an incomplete escape sequence is encountered. The Escape keypress event is only emitted If the wait elapses before any more characters are encountered.