johnnovak / illwill

A curses inspired simple cross-platform console library for Nim
Do What The F*ck You Want To Public License
398 stars 27 forks source link

Keypresses not detected while mouse is moving #24

Closed thetek42 closed 2 years ago

thetek42 commented 3 years ago

When you try to detect keypresses, they won't get detected when the mouse is moving at the same time.

Steps to reproduce:

System Details:

enthus1ast commented 3 years ago

Would be interesting to see if the key presses reach the terminal input buffer at all if the mouse is moving (mouse coordinates also gets reported via terminal buffer), if yes its a bug

thetek42 commented 3 years ago

My guess is that any other key simply gets overridden if the mouse is active.

From illwill.nim, line 642 onwards:

proc parseKey(charsRead: int): Key =
    var key = Key.None
    if charsRead == 1:
        let ch = keyBuf[0]
        case ch: #...
        ### Tab, Enter, Escape, Space and Backspace keys
    else:
        key = toKey(ch)

    elif charsRead > 3 and keyBuf[0] == 27 and keyBuf[1] == 91 and keyBuf[2] == 60: # TODO what are these :)
        fillGlobalMouseInfo(keyBuf)
        ### Key.Mouse is returned 
        return Key.Mouse

    else:
        ### other keys
    result = key

It would be neat if you could access keyboard keys with Key.Whatever, and the mouse with Mouse. This separation would also get rid of the bug, as the keypresses would not get overridden anymore as soon as mouse movement is detected.

johnnovak commented 3 years ago

If it's a bug, and it's fixable, maybe you can ask @enthus1ast nicely to raise a PR 😄 He introduced mouse support in the first place, I don't really need it and care too much for it, so it's unlikely I will work on this anytime soon.

johnnovak commented 2 years ago

Closing due to inactivity/lack of interest.