I tried the same code on each platform - from the examples:
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)
main()
On the Pi - Raspbian GNU/Linux 10 (buster), Python 3.7.3:
Traceback (most recent call last):
File "/home/pi/.local/lib/python3.7/site-packages/inputs.py", line 3658, in get_key
keyboard = devices.keyboards[0]
IndexError: list index out of range
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/pi/Desktop/minimal.py", line 14, in <module>
main()
File "/home/pi/Desktop/minimal.py", line 9, in main
events = get_key()
File "/home/pi/.local/lib/python3.7/site-packages/inputs.py", line 3660, in get_key
raise UnpluggedError("No keyboard found.")
inputs.UnpluggedError: No keyboard found.
(FWIW, this was in a VNC session.)
On Windows 10, Python 3.8.5:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Program_Files\anaconda3\lib\multiprocessing\spawn.py", line 116, in spawn_main
exitcode = _main(fd, parent_sentinel)
File "C:\Program_Files\anaconda3\lib\multiprocessing\spawn.py", line 125, in _main
prepare(preparation_data)
File "C:\Program_Files\anaconda3\lib\multiprocessing\spawn.py", line 236, in prepare
_fixup_main_from_path(data['init_main_from_path'])
File "C:\Program_Files\anaconda3\lib\multiprocessing\spawn.py", line 287, in _fixup_main_from_path
main_content = runpy.run_path(main_path,
File "C:\Program_Files\anaconda3\lib\runpy.py", line 265, in run_path
return _run_module_code(code, init_globals, run_name,
File "C:\Program_Files\anaconda3\lib\runpy.py", line 97, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "C:\Program_Files\anaconda3\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "C:\Users\Dave\data\Code\Python\lib\minimal.py", line 14, in <module>
main()
File "C:\Users\Dave\data\Code\Python\lib\minimal.py", line 9, in main
events = get_key()
File "C:\Program_Files\anaconda3\lib\site-packages\inputs.py", line 3661, in get_key
return keyboard.read()
File "C:\Program_Files\anaconda3\lib\site-packages\inputs.py", line 2517, in read
return next(iter(self))
File "C:\Program_Files\anaconda3\lib\site-packages\inputs.py", line 2471, in __iter__
event = self._do_iter()
File "C:\Program_Files\anaconda3\lib\site-packages\inputs.py", line 2495, in _do_iter
data = self._get_data(read_size)
File "C:\Program_Files\anaconda3\lib\site-packages\inputs.py", line 2575, in _get_data
return self._pipe.recv_bytes()
File "C:\Program_Files\anaconda3\lib\site-packages\inputs.py", line 2534, in _pipe
self._listener.start()
File "C:\Program_Files\anaconda3\lib\multiprocessing\process.py", line 121, in start
self._popen = self._Popen(self)
File "C:\Program_Files\anaconda3\lib\multiprocessing\context.py", line 224, in _Popen
return _default_context.get_context().Process._Popen(process_obj)
File "C:\Program_Files\anaconda3\lib\multiprocessing\context.py", line 327, in _Popen
return Popen(process_obj)
File "C:\Program_Files\anaconda3\lib\multiprocessing\popen_spawn_win32.py", line 45, in __init__
prep_data = spawn.get_preparation_data(process_obj._name)
File "C:\Program_Files\anaconda3\lib\multiprocessing\spawn.py", line 154, in get_preparation_data
_check_not_importing_main()
File "C:\Program_Files\anaconda3\lib\multiprocessing\spawn.py", line 134, in _check_not_importing_main
raise RuntimeError('''
RuntimeError:
An attempt has been made to start a new process before the
current process has finished its bootstrapping phase.
This probably means that you are not using fork to start your
child processes and you have forgotten to use the proper idiom
in the main module:
if __name__ == '__main__':
freeze_support()
...
The "freeze_support()" line can be omitted if the program
is not going to be frozen to produce an executable.
Exception ignored in: <function InputDevice.__del__ at 0x0000016F36E2AF70>
Traceback (most recent call last):
File "C:\Program_Files\anaconda3\lib\site-packages\inputs.py", line 2541, in __del__
File "C:\Program_Files\anaconda3\lib\multiprocessing\process.py", line 133, in terminate
AttributeError: 'NoneType' object has no attribute 'terminate'
(FWIW, I tried in Spyder as installed by Anaconda.)
I tried the same code on each platform - from the examples:
On the Pi - Raspbian GNU/Linux 10 (buster), Python 3.7.3:
(FWIW, this was in a VNC session.)
On Windows 10, Python 3.8.5:
(FWIW, I tried in Spyder as installed by Anaconda.)