Skip to content

Calling getkey(blocking=False) results in missed keyboard inputs #17

@d0ivanov

Description

@d0ivanov

Using getkey==0.6.5 on Fedora 31.

$ uname -a
Linux localhost.localdomain 5.8.16-100.fc31.x86_64 #1 SMP Mon Oct 19 14:16:07 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

$ python --version
Python 3.7.9

I have this small program:

from getkey import getkey
import time

for i in range(10):
    time.sleep(0.5)
    print("READ: {}".format(getkey(blocking=False)))

When I run it and type some random input on my keyboard (for example "asdf") I would expect the result to be something similar to the following:

$ python program.py 
asdf
READ: a
READ: s
READ: d
READ: f

But instead I get nothing. Meaning that my input is not printed back to me.

$ python program.py 
asdf
READ:
READ:
READ:
READ:

I suspect that this happens because, when tty.setcbreak is called to make all inputs immediately available for reading on UNIX platforms, the when argument is not passed so its default value of termios.TCSAFLUSH is used. This means that the cbreak property will be in effect after transmitting all queued output and discarding all queued input which may not happen immediately so some inputs will be lost.

References: https://docs.python.org/3/library/tty.html and https://docs.python.org/3/library/termios.html#termios.tcsetattr

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions