Browse Source

Fix joystick initialization and update button press handling in KeyLogger

master
Matteo Benedetto 4 months ago
parent
commit
5e0f375948
  1. 4
      key.py

4
key.py

@ -12,6 +12,8 @@ class KeyLogger:
# Initialize joystick support # Initialize joystick support
sdl2.SDL_Init(sdl2.SDL_INIT_JOYSTICK) sdl2.SDL_Init(sdl2.SDL_INIT_JOYSTICK)
sdl2.SDL_JoystickOpen(0) sdl2.SDL_JoystickOpen(0)
sdl2.SDL_JoystickOpen(1) # Open the first joystick
sdl2.SDL_JoystickEventState(sdl2.SDL_ENABLE)
self.window = sdl2.ext.Window("Key Logger", size=(640, 480)) self.window = sdl2.ext.Window("Key Logger", size=(640, 480))
self.window.show() self.window.show()
self.running = True self.running = True
@ -37,7 +39,7 @@ class KeyLogger:
elif event.type == sdl2.SDL_JOYBUTTONDOWN: elif event.type == sdl2.SDL_JOYBUTTONDOWN:
button = event.jbutton.button button = event.jbutton.button
self.message = f"Joystick button {button} pressed" self.message = f"Joystick button {button} pressed"
if button == 0: # Assuming button 0 is the right trigger if button == 9: # Assuming button 0 is the right trigger
self.running = False self.running = False
elif event.type == sdl2.SDL_QUIT: elif event.type == sdl2.SDL_QUIT:
self.running = False self.running = False

Loading…
Cancel
Save