我正在尝试使用 pygame

问题描述

没有使用显示器,只是在我点击某物后,操纵杆检测就停止了。问题是当我按下模拟点击的按钮时,操纵杆运动停止。

import pygame
import pyautogui
import keyboard

pygame.init()

size = (5,5)
screen = pygame.display.set_mode(size)

#x,y = pyautogui.position()
joysticks = []

for i in range(pygame.joystick.get_count()):
    joysticks.append(pygame.joystick.Joystick(i))
    joysticks[-1].init()


while True:
    x,y = pyautogui.position()
    if keyboard.is_pressed('q'):
        break
    for event in pygame.event.get():
        if event.type == pygame.JOYBUTTONDOWN:
            if event.button == 0:
                pyautogui.click()
        if event.type == pygame.JOYAXISMOTION:
            print(event.axis)
            print(event.value)
            if event.axis == 4 or event.axis == 0:
                if event.value > 0.25:
                    x += 25
                elif event.value < - 0.25:
                    x -= 25
            if event.axis == 3 or event.axis == 1:
                if event.value > 0.25:
                    y += 25
                elif event.value < -0.25:
                    y -= 25
    pyautogui.moveto(x,y)

    screen.fill((0,255))
    pygame.display.flip()
            

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)