简体   繁体   中英

Steam not detecting python-uinput

I'm trying to make a custom input device using an Arduino and python-uinput but Steam is simply not detecting it. If I navigate to Settings/Controller/General Controller Settings/ it shows no devices. The virtual device shows up just fine in the OS joystick manager as /dev/input/js0 . What's weird is that this used to work - a prototype I made in June worked with the same code.

A very similar question was posted here but it never got an answer.

Minimal example:

import uinput
import math
import time

events = (uinput.BTN_JOYSTICK, uinput.ABS_X + (0, 255, 0, 0), uinput.ABS_Y + (0, 255, 0, 0), uinput.ABS_Z + (0, 255, 0, 0))

device = uinput.Device(events)
device.emit(uinput.ABS_X, 128, syn=False)
device.emit(uinput.ABS_Y, 128, syn=False)
device.emit(uinput.ABS_Z, 128, syn=False)

total = 0

while True:
    device.emit(uinput.ABS_X, int(math.sin(total) * 128 + 127))
    time.sleep(0.1)
    total += 0.1

I do also use a wired USB joystick with this computer, however it was unplugged at the time of testing. OS is Manjaro Linux with KDE Plasma, X11. The specific game I'm trying to use the controller in is running in Proton.

SOLVED!!

It appears Steam wasn't happy with the lack of buttons on the virtual device. Adding a bunch of unused buttons makes it work:

import uinput
import math
import time

events = (uinput.BTN_JOYSTICK,
    uinput.ABS_X + (0, 255, 0, 0), uinput.ABS_Y + (0, 255, 0, 0), uinput.ABS_Z + (0, 255, 0, 0),
    uinput.ABS_RX,
    uinput.BTN_0, uinput.BTN_1, uinput.BTN_2, uinput.BTN_3, uinput.BTN_4, uinput.BTN_5, uinput.BTN_6, uinput.BTN_7, uinput.BTN_8, uinput.BTN_9)

device = uinput.Device(events)
time.sleep(1) # give device some time to set up

device.emit(uinput.ABS_X, 128, syn=False)
device.emit(uinput.ABS_Y, 128, syn=False)
device.emit(uinput.ABS_Z, 128, syn=False)
            
total = 0

while True:
    device.emit(uinput.ABS_X, int(math.sin(total) * 128 + 127))
    time.sleep(0.1)
    total += 0.1

If that still doesn't work, try sending a few fake button presses through before your main code:

device.emit(uinput.ABS_RX, 0)
device.emit(uinput.BTN_JOYSTICK, 0)
device.emit(uinput.BTN_0, 0)
device.emit(uinput.BTN_1, 0)
device.emit(uinput.BTN_2, 0)
device.emit(uinput.BTN_3, 0)
device.emit(uinput.BTN_4, 0)
device.emit(uinput.BTN_5, 0)
device.emit(uinput.BTN_6, 0)
device.emit(uinput.BTN_7, 0)
device.emit(uinput.BTN_8, 0)
device.emit(uinput.BTN_9, 0)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM