Simulating controller dpad button being held down with Python evdev

只谈情不闲聊 提交于 2021-01-27 20:32:21

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!