boppreh / keyboard

Hook and simulate global keyboard events on Windows and Linux.
MIT License
3.81k stars 435 forks source link

IOError: [Errno 25] Inappropriate ioctl for device (Linux, buildroot) #126

Open Sjoerd82 opened 6 years ago

Sjoerd82 commented 6 years ago

Running the Example from the Readme.md, I am greeted with:

Traceback (most recent call last):
  File "example.py", line 3, in <module>
    keyboard.press_and_release('shift+s, space')
  File "/root/defender-headunit/keyboard/__init__.py", line 639, in press_and_release
    send(combination, True, True)
  File "/root/defender-headunit/keyboard/__init__.py", line 623, in send
    _os_keyboard.press(to_scan_code(key))
  File "/root/defender-headunit/keyboard/_nixkeyboard.py", line 157, in press
    write_event(scan_code, True)
  File "/root/defender-headunit/keyboard/_nixkeyboard.py", line 142, in write_event
    build_device()
  File "/root/defender-headunit/keyboard/_nixkeyboard.py", line 107, in build_device
    device = aggregate_devices('kbd')
  File "/root/defender-headunit/keyboard/_nixcommon.py", line 141, in aggregate_devices
    uinput = make_uinput()
  File "/root/defender-headunit/keyboard/_nixcommon.py", line 29, in make_uinput
    fcntl.ioctl(uinput, UI_SET_EVBIT, EV_KEY)
IOError: [Errno 25] Inappropriate ioctl for device

My /dev/uinput:

-rw-r--r--    1 root     root           0 Jan  1 00:37 /dev/uinput

My /dev/input

drwxr-xr-x    4 root     root         140 Jan  1 00:00 .
drwxr-xr-x   11 root     root        3.0K Jan  1 00:31 ..
drwxr-xr-x    2 root     root          80 Jan  1 00:00 by-id
drwxr-xr-x    2 root     root          80 Jan  1 00:00 by-path
crw-rw----    1 root     input      13,  64 Jan  1 00:00 event0
crw-rw----    1 root     input      13,  65 Jan  1 00:00 event1
crw-rw----    1 root     input      13,  63 Jan  1 00:00 mice

by-id:

drwxr-xr-x    2 root     root          80 Jan  1 00:00 .
drwxr-xr-x    4 root     root         140 Jan  1 00:00 ..
lrwxrwxrwx    1 root     root           9 Jan  1 00:00 usb-GASIA_GASIA_USB_KB_Pro-event-if01 -> ../event1
lrwxrwxrwx    1 root     root           9 Jan  1 00:00 usb-GASIA_GASIA_USB_KB_Pro-event-kbd -> ../event0

by-path:

drwxr-xr-x    2 root     root          80 Jan  1 00:00 .
drwxr-xr-x    4 root     root         140 Jan  1 00:00 ..
lrwxrwxrwx    1 root     root           9 Jan  1 00:00 platform-20980000.usb-usb-0:1.2:1.0-event-kbd -> ../event0
lrwxrwxrwx    1 root     root           9 Jan  1 00:00 platform-20980000.usb-usb-0:1.2:1.1-event -> ../event1

I'm running as root. Distribution is Buildroot. Perhaps I'm missing libs? But I have the kbd libs.

boppreh commented 6 years ago

Sorry for the delay looking into this issue, I was without a Linux machine for a while.

I think the problem is that your system doesn't have the uinput module. keyboard tries to open the file /dev/uinput expecting to create a new device, but ends up just creating a regular file at that location. This can be seen by the mode of the file, -rw-r--r--, instead of crw-------, where c means "character special file".

uinput is used to ensure we can always send any keys without depending on physical keyboard limitations, or even the presence of a physical keyboard. If your system has a plugged in keyboard we can try removing the dependency on uinput; if it doesn't have either uinput or a plugged in keyboard, I'm out of ideas.

Additionally, I'll add a check to ensure uinput exists before trying to create the file.

boppreh commented 6 years ago

Missing uinput shouldn't error out anymore. Please give the master branch a try and tell me if that fixes your problem.

Sjoerd82 commented 6 years ago

I'll retest soon, I'll let you know.

hmusgrave commented 4 years ago

I have the same error on the master branch.

Edit: Enabling uinput in the kernel fixes everything.