i dont know how do i make it if ex. x axis is 254 and y axis is 254 it should only type one r and not spam r, i really dont know how i can fix it , someone please help
import pygame
import time
import sys
from pynput.keyboard import Key, Controller
keyboard = Controller()
# Initialize pygame
pygame.init()
# Set up the joystick
if pygame.joystick.get_count() == 0:
print("No joystick connected!")
sys.exit()
joystick = pygame.joystick.Joystick(0)
joystick.init()
print(f"Joystick detected: {joystick.get_name()}")
# Main loop
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.JOYAXISMOTION:
x_axis = int((joystick.get_axis(0) + 1) * 127.5) # Scale to 0-255
y_axis = int((joystick.get_axis(1) + 1) * 127.5) # Scale to 0-255
print(f"x: {x_axis}, y: {y_axis}")
if x_axis == 0 and y_axis == 254:
keyboard.press('2')
if x_axis == 0 and y_axis == 0:
keyboard.press('1')
if x_axis == 254 and y_axis == 254:
keyboard.press('r')
if x_axis == 254 and y_axis == 0:
keyboard.press('5')
if x_axis == 126 and y_axis == 254:
keyboard.press('4')
if x_axis == 126 and y_axis == 0:
keyboard.press('3')
pygame.time.wait(100)
pygame.quit()
i tried to use time.sleep but it didnt work
New contributor
xXOVKLXx is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.