Skip to content

Commit

Permalink
Fix issue boppreh#397: Event listener fails when keyboard is disconne…
Browse files Browse the repository at this point in the history
…cted momentarily.

I encountered the issue in a *nix machine (Ubuntu 16.04).
The fix makes it so that we don't ready the input file when a keyboard is
disconnected by checking the 'readable()' method on the file pointer, in Ubuntu
when the keyboard is re-connected the 'readable()' method returns True and
everything works as usual.
  • Loading branch information
marcel-valdez committed Mar 26, 2021
1 parent 233fd11 commit 9ce2e3f
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion keyboard/_nixcommon.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ def __init__(self, devices, output=None):
self.output = output or self.devices[0]
def start_reading(device):
while True:
self.event_queue.put(device.read_event())
if device.input_file.readable():
self.event_queue.put(device.read_event())
for device in self.devices:
thread = Thread(target=start_reading, args=[device])
thread.setDaemon(True)
Expand Down

0 comments on commit 9ce2e3f

Please sign in to comment.