问题
I'm trying to simulate holding down a DPad button on a controller using Python evdev.
So far I've managed to successfully press a button like so:
import os
import time
from evdev import uinput, ecodes as e, list_devices, InputDevice, ff
dev = InputDevice(str(os.path.realpath("/dev/input/by-id/usb-Sony_Interactive_Entertainment_Wireless_Controller-if03-event-joystick")))
dev.write(e.EV_ABS, e.ABS_HAT0X, 1)
dev.write(e.EV_ABS, e.ABS_HAT0X, 0)
dev.write(e.EV_SYN, 0, 0)
but haven't been able to successfully have the application I'm simulating the input for detect the button held for any amount of time. What I've tried is this (and a couple variations on this)
...
dev.write(e.EV_ABS, e.ABS_HAT0X, 2) # evdev docs say 2 is for holding
dev.write(e.EV_SYN, 0, 0)
time.sleep(2)
dev.write(e.EV_ABS, e.ABS_HAT0X, 0)
dev.write(e.EV_SYN, 0, 0)
What am I doing wrong?
来源:https://stackoverflow.com/questions/62128479/simulating-controller-dpad-button-being-held-down-with-python-evdev