Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
452 views
in Technique[技术] by (71.8m points)

python - I am trying to control mouse movement with an xbox controller using pygame

The display is not used, it's just the fact that after I click on something, the joystick detection just stops. The problem is that when I press the a button which emulates a click, the joystick movement stops.

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, 0, 255))
    pygame.display.flip()
            
question from:https://stackoverflow.com/questions/66049843/i-am-trying-to-control-mouse-movement-with-an-xbox-controller-using-pygame

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...