1

我正在尝试构建一个arcade machine使用Beaglebone Black GPIO开关的Happs controller set. 我构建了一个python script在启动时运行并将所有 GPIO 正确分配给Advmenu and Advmame. 该脚本在命令行上运行良好,但我无法uinput在里面工作Advmenu or Advmame。我已尝试对udev规则进行多次更改,但均未成功。目前似乎SDL1.2是已安装的SDL版本,但目前我正在构建最新的SDL2.

udev 文件 /etc/udev/rules.d/40-uinput.rules

SUBSYSTEM=="input", KERNEL=="uinput", MODE="0666", GROUP="uinput", ATTRS{name}=="arcade", ENV{ID_INPUT_KEYBOARD}="1"

这是我创建并一直在使用的程序

import Adafruit_BBIO.GPIO as GPIO
import uinput
import time

GPIO.setup("P9_11", GPIO.IN) #Player 1 Button 1
GPIO.setup("P9_13", GPIO.IN) #Player 1 Button 2
GPIO.setup("P9_15", GPIO.IN) #Player 1 Button 3
GPIO.setup("P9_17", GPIO.IN) #Player 1 Button 4
GPIO.setup("P9_21", GPIO.IN) #Player 1 Button 5
GPIO.setup("P9_23", GPIO.IN) #Player 1 Button 6

GPIO.setup("P9_12", GPIO.IN) #Player 2 Button 1
GPIO.setup("P9_14", GPIO.IN) #Player 2 Button 2
GPIO.setup("P9_16", GPIO.IN) #Player 2 Button 3
GPIO.setup("P9_18", GPIO.IN) #Player 2 Button 4
GPIO.setup("P9_22", GPIO.IN) #Player 2 Button 5
GPIO.setup("P9_24", GPIO.IN) #Player 2 Button 6

GPIO.setup("P9_25", GPIO.IN) #Select 1 Player
GPIO.setup("P9_26", GPIO.IN) #Select 2 Player
GPIO.setup("P9_27", GPIO.IN) # Coin

GPIO.setup("P8_7", GPIO.IN) #Player 1 Button Up
GPIO.setup("P8_9", GPIO.IN) #Player 1 Button Down
GPIO.setup("P8_11", GPIO.IN) #Player 1 Button Left
GPIO.setup("P8_13", GPIO.IN) #Player 1 Button Right

GPIO.setup("P8_8", GPIO.IN) #Player 2 Button Up
GPIO.setup("P8_10", GPIO.IN) #Player 2 Button Down
GPIO.setup("P8_12", GPIO.IN) #Player 2 Button Left
GPIO.setup("P8_14", GPIO.IN) #Player 2 Button Right

device = uinput.Device([
    uinput.KEY_LEFTCTRL, #Player 1 Button 1
    uinput.KEY_LEFTALT, #Player 1 Button 2
    uinput.KEY_SPACE, #Player 1 Button 3
    uinput.KEY_LEFTSHIFT, #Player 1 Button 4
    uinput.KEY_A, #Player 1 Button 5
    uinput.KEY_S, #Player 1 Button 6
    uinput.KEY_Q, #Player 2 Button 1
    uinput.KEY_W, #Player 2 Button 2
    uinput.KEY_I, #Player 2 Button 3
    uinput.KEY_J, #Player 2 Button 4
    uinput.KEY_K, #Player 2 Button 5
    uinput.KEY_L, #Player 2 Button 6
    uinput.KEY_1, #Select Player 1
    uinput.KEY_2, #Select Player 2
    uinput.KEY_5, #Coin
    uinput.KEY_UP, #Player 1 Button Up
    uinput.KEY_DOWN, #Player 1 Button Down
    uinput.KEY_LEFT, #Player 1 Button Left
    uinput.KEY_RIGHT, #Player 1 Button Right
    uinput.KEY_R, #Player 2 Button Up
    uinput.KEY_F, #Player 2 Button Down
    uinput.KEY_D, #Player 2 Button Left
    uinput.KEY_G #Player 2 Button Right
    ])

old_switch_state = 0
loop1 = 0
s = 0.02

while (loop1 == 0):

new_switch_state_P1_1 = GPIO.input("P9_11")
new_switch_state_P1_2 = GPIO.input("P9_13")
new_switch_state_P1_3 = GPIO.input("P9_15")
new_switch_state_P1_4 = GPIO.input("P9_17")
new_switch_state_P1_5 = GPIO.input("P9_21")
new_switch_state_P1_6 = GPIO.input("P9_23")
new_switch_state_P2_1 = GPIO.input("P9_12")
new_switch_state_P2_2 = GPIO.input("P9_14")
new_switch_state_P2_3 = GPIO.input("P9_16")
new_switch_state_P2_4 = GPIO.input("P9_18")
new_switch_state_P2_5 = GPIO.input("P9_22")
new_switch_state_P2_6 = GPIO.input("P9_24")

new_switch_state_S1 = GPIO.input("P9_25")
new_switch_state_S2 = GPIO.input("P9_26")
new_switch_state_C = GPIO.input("P9_27")

new_switch_state_P1_U = GPIO.input("P8_7")
new_switch_state_P1_D = GPIO.input("P8_9")
new_switch_state_P1_L = GPIO.input("P8_11")
new_switch_state_P1_R = GPIO.input("P8_13")
new_switch_state_P2_U = GPIO.input("P8_8")
new_switch_state_P2_D = GPIO.input("P8_10")
new_switch_state_P2_L = GPIO.input("P8_12")
new_switch_state_P2_R = GPIO.input("P8_14")

if new_switch_state_P1_1 == 1 :
    device.emit_click(uinput.KEY_LEFTCTRL)

if new_switch_state_P1_2 == 1 :
    device.emit_click(uinput.KEY_LEFTALT)

if new_switch_state_P1_3 == 1 :
    device.emit_click(uinput.KEY_SPACE)

if new_switch_state_P1_4 == 1 :
    device.emit_click(uinput.KEY_LEFTSHIFT)

if new_switch_state_P1_5 == 1 :
    device.emit_click(uinput.KEY_Z)

if new_switch_state_P1_6 == 1 :
    device.emit_click(uinput.KEY_X)

if new_switch_state_P2_1 == 1 :
    device.emit_click(uinput.KEY_A)

if new_switch_state_P2_2 == 1 :
    device.emit_click(uinput.KEY_S)

if new_switch_state_P2_3 == 1 :
    device.emit_click(uinput.KEY_Q)

if new_switch_state_P2_4 == 1 :
    device.emit_click(uinput.KEY_W)

if new_switch_state_P2_5 == 1 :
    device.emit_click(uinput.KEY_K)

if new_switch_state_P2_6 == 1 :
    device.emit_click(uinput.KEY_L)

if new_switch_state_S1 == 1 :
    device.emit_click(uinput.KEY_M)

if new_switch_state_S2 == 1 :
    device.emit_click(uinput.KEY_N)

if new_switch_state_C == 1 :
    device.emit_click(uinput.KEY_O)

if new_switch_state_P1_U == 1 :
    device.emit_click(uinput.KEY_UP)

if new_switch_state_P1_D == 1 :
    device.emit_click(uinput.KEY_DOWN)

if new_switch_state_P1_L == 1 :
    device.emit_click(uinput.KEY_LEFT)

if new_switch_state_P1_R == 1 :
    device.emit_click(uinput.KEY_RIGHT)

if new_switch_state_P2_U == 1 :
    device.emit_click(uinput.KEY_R)

if new_switch_state_P2_D == 1 :
    device.emit_click(uinput.KEY_F)

if new_switch_state_P2_L == 1 :
    device.emit_click(uinput.KEY_D)

if new_switch_state_P2_R == 1 :
    device.emit_click(uinput.KEY_G)
time.sleep(s)

任何想法为什么虚拟键盘不起作用?

4

0 回答 0