gvalkov / python-evdev

Python bindings for the Linux input subsystem
https://python-evdev.rtfd.org/
BSD 3-Clause "New" or "Revised" License
322 stars 108 forks source link

evdev.UInput is working when retropie is running but not working when the game is running #92

Open mdasifbinkhaled opened 6 years ago

mdasifbinkhaled commented 6 years ago

This program works fine while the retro pie runs but it does not work when the game/ROM runs. @gvalkov can you please tell me what is the bug?

from evdev import UInput,ecodes as e
import time

ui=UInput()

def hold(key):
ui.write(e.EV_KEY, key, 1)
ui.syn()
return 0

def release(key):
ui.write(e.EV_KEY, key, 0)
ui.syn()
return 0

hold(e.KEY_E)
time.sleep(1)
release(e.KEY_E)
#ui.close()
LinusCDE commented 3 years ago

My guess would be that the Emulator doesn't accept the device since it didn't define any capabilities.

Any system that takes input from the linux input event subsystem (the part you inject a device with events to) usually wants to classify the inputs devices it finds.

This is done though capabilities (or called events, whatever). It is recommended that you add every event you may ever send as a capability.

The retropi main menu might not care about that in its implementation but certain emulator may probably want to know whether you are a poorly implemented Joystick or an actual keyboard.

Therefore try to replace ui=UInput() with:

capabilities = { e.EV_KEY: [e.KEY_E] }
ui=UInput(events=capabilities)