You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

vgamepad库问题:DS4手柄控制堡垒之夜按L2后仅L2可操控车辆

问题描述

我用Python的vgamepad库实现DS4手柄输入控制《堡垒之夜》,配置完成后其他控制均正常,但车辆控制存在异常:匹配开始时车辆所有控制正常,按下L2后仅L2可操控车辆,其他控制失效;暂不清楚其他游戏是否存在此问题。

代码实现
from pygame import init,joystick as j
from pygame.event import get
from vgamepad import VDS4Gamepad,VX360Gamepad
from time import sleep,time
init()
j.init()
gamepad = VDS4Gamepad()
joystick = None
condition = True
platform = 'ps4'
incluer2 = False
incluel2 = False
incluer = True
incluel = True
r2round = 3
l2round = 3
rround = 2
lround = 2
st = .01
wt = 1.044
def ps4():
    global joystick
    while condition:
        while j.get_count() == 0:
            sleep(1)
        if joystick is not None and not joystick.get_init():
            joystick = None
        if joystick == None:
            joystick = j.Joystick(0)
            joystick.init()
        get()
        if joystick.get_axis(4) > -0.5:
            gamepad.press_button(1024)
        else:
            gamepad.release_button(1024)
        if joystick.get_axis(5) > -0.5:
            gamepad.press_button(2048)
        else:
            gamepad.release_button(2048)
        if joystick.get_button(0):
            gamepad.press_button(32)
        else:
            gamepad.release_button(32)
        if joystick.get_button(1):
            gamepad.press_button(64)
        else:
            gamepad.release_button(64)
        if joystick.get_button(2):
            gamepad.press_button(16)
        else:
            gamepad.release_button(16)
        if joystick.get_button(3):
            gamepad.press_button(128)
        else:
            gamepad.release_button(128)
        if joystick.get_button(4):
            gamepad.press_button(4096)
        else:
            gamepad.release_button(4096)
        if joystick.get_button(5):
            gamepad.press_special_button(1)
        else:
            gamepad.release_special_button(1)
        if joystick.get_button(6):
            gamepad.press_button(8192)
        else:
            gamepad.release_button(8192)
        if joystick.get_button(7):
            gamepad.press_button(16384)
        else:
            gamepad.release_button(16384)
        if joystick.get_button(8):
            gamepad.press_button(32768)
        else:
            gamepad.release_button(32768)
        if joystick.get_button(9):
            gamepad.press_button(256)
        else:
            gamepad.release_button(256)
        if joystick.get_button(10):
            gamepad.press_button(512)
        else:
            gamepad.release_button(512)
        if joystick.get_button(11):
            gamepad.directional_pad(0)
        elif joystick.get_button(12):
            gamepad.directional_pad(4)
        elif joystick.get_button(13):
            gamepad.directional_pad(6)
        elif joystick.get_button(14):
            gamepad.directional_pad(2)
        else:
            gamepad.directional_pad(10)
        if joystick.get_button(15):
            gamepad.press_special_button(2)
        else:
            gamepad.release_special_button(2)
        gamepad.left_joystick_float(x_value_float=joystick.get_axis(0), y_value_float=joystick.get_axis(1))
        gamepad.right_joystick_float(x_value_float=joystick.get_axis(2), y_value_float=joystick.get_axis(3))
        gamepad.left_trigger_float(joystick.get_axis(4))
        gamepad.right_trigger_float(joystick.get_axis(5))
        gamepad.update()
        sleep(st)
ps4()

内容的提问来源于stack exchange,提问作者FrostDream

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.02 23:54:52