zeth / inputs

Cross-platform Python support for keyboards, mice and gamepads
BSD 3-Clause "New" or "Revised" License
269 stars 87 forks source link

Keyboard blocking while no input #78

Closed ItsChoudhry closed 4 years ago

ItsChoudhry commented 5 years ago

Hey while working with the keyboard stuff I noticed if there is no input the the execution is blocked.

from __future__ import print_function

from inputs import get_key

def main():
    """Just print out some event infomation when keys are pressed."""
    while 1:
        events = get_key()
        if events:
            for event in events:
                print(event.ev_type, event.code, event.state)
        print("Hello")
        sleep(0.1)

if __name__ == "__main__":
    main()

If you run the following code you'll notice that Hello doesn't print until you press a key. After some further digging I found that it's halting in the _get_data(self, read_size)

    def _get_data(self, read_size):
        """Get data from the character device."""
        return self._character_device.read(read_size) <-- here waiting on a input

I did some digging and couldn't find anything to help stop it from blocking. So if anyone else any ideas please and thank you.

ErikOrjehag commented 4 years ago

Hey! Look at issue #7 , I found a solution that worked for me

ItsChoudhry commented 4 years ago

This seems to be solved