keyboard icon indicating copy to clipboard operation
keyboard copied to clipboard

An OSError when the device is unplugged on RaspberrypiOS

Open H3LL0U opened this issue 11 months ago • 2 comments

When the device is unplugged during the execution of the following code:

import keyboard

if __name__ == "__main__":
    keyboard.wait('esc')

The following error acures which breaks the program:

Exception in thread Thread-2:
Traceback (most recent call last):
  File "/usr/lib/python3.9/threading.py", line 954, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.9/threading.py", line 892, in run
    self._target(*self._args, **self._kwargs)
Exception in thread Thread-3:
Traceback (most recent call last):
  File "/usr/lib/python3.9/threading.py", line 954, in _bootstrap_inner
Exception in thread Thread-4:
Traceback (most recent call last):
  File "/usr/lib/python3.9/threading.py", line 954, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.9/threading.py", line 892, in run
  File "/usr/local/lib/python3.9/dist-packages/keyboard/_nixcommon.py", line 106, in start_reading
    self.event_queue.put(device.read_event())
  File "/usr/local/lib/python3.9/dist-packages/keyboard/_nixcommon.py", line 83, in read_event
    self.run()
  File "/usr/lib/python3.9/threading.py", line 892, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/local/lib/python3.9/dist-packages/keyboard/_nixcommon.py", line 106, in start_reading
    self.event_queue.put(device.read_event())
  File "/usr/local/lib/python3.9/dist-packages/keyboard/_nixcommon.py", line 83, in read_event
    data = self.input_file.read(struct.calcsize(event_bin_format))
OSError: [Errno 19] No such device
    data = self.input_file.read(struct.calcsize(event_bin_format))
OSError: [Errno 19] No such device
    self._target(*self._args, **self._kwargs)
  File "/usr/local/lib/python3.9/dist-packages/keyboard/_nixcommon.py", line 106, in start_reading
    self.event_queue.put(device.read_event())
  File "/usr/local/lib/python3.9/dist-packages/keyboard/_nixcommon.py", line 83, in read_event
    data = self.input_file.read(struct.calcsize(event_bin_format))
OSError: [Errno 19] No such device

Note: I'm starting the Script through SSH with sudo python3 Log.py and the Script executes normally when the keyboard is innitially plugged in

H3LL0U avatar Mar 13 '24 15:03 H3LL0U

https://github.com/boppreh/keyboard/issues/531 Similar Issue

H3LL0U avatar Mar 13 '24 16:03 H3LL0U

Partial solution found. Now the keyboard doesn't raise an OSError when disconected. However upon disconecting it reinitializes everything which automatically sets a fake keyboard. The system should be implomented which checks if there are any changes in the usb devices 5d518fa4fe4083475e913d580ccf1b8126c4d72e (Will work on it later)

H3LL0U avatar Mar 13 '24 22:03 H3LL0U