0

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()
            
Rabbid76
  • 202,892
  • 27
  • 131
  • 174
  • Can you please clarify what you are doing (where) and what you are observing (where)? – Wolf Feb 04 '21 at 16:36
  • Do you mean that you observe movement until the first click? Please integrate details into the question! – Wolf Feb 04 '21 at 16:40
  • Yes, there is movement until the first click. Then it stops all of a sudden – Julien Serbanescu Feb 04 '21 at 17:34
  • Any errors messages or other hints? Do you know that you may also print to the console from an PyGame application? Please use the [edit](https://stackoverflow.com/posts/66049843/edit) function to improve the question. – Wolf Feb 04 '21 at 19:34
  • This script seems to do what you want: https://github.com/Daniel-Chin/Python_Lib/blob/master/joystick_cursor.py – Daniel Chin Feb 16 '22 at 16:38

0 Answers0