Skip to content

Commit 99fb97f

Browse files
committed
joy2key: fix spurious initialization events
For certain joysticks (axis), SDL will generate spurious axis movement events during initialization. It seems that for axis where `absmin` and `absmax` are asymmetrical (ex. 0-255 instead of -255 - 255), SDL generates extra events which are not user generated. This can causes issues - i.e. automatically trigger the `runcommand` menu without user interaction, unintended scrolling, etc. As a workaround, discard any axis movement events _immediately_ after the device is added. NOTE: this will discard any potential valid axis events from another (already connected) device if they are present, forcing the user to probably re-center the joystick they were using.
1 parent 4341e2f commit 99fb97f

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

scriptmodules/admin/joy2key/joy2key_sdl.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
from sdl2 import joystick, events, version, \
3939
SDL_WasInit, SDL_Init, SDL_QuitSubSystem, SDL_GetError, \
4040
SDL_INIT_JOYSTICK, SDL_INIT_VIDEO, version_info, \
41-
SDL_Event, SDL_PollEvent, SDL_Delay, SDL_Quit, \
41+
SDL_Event, SDL_PollEvent, SDL_FlushEvent, SDL_Delay, SDL_Quit, \
4242
SDL_JOYDEVICEADDED, SDL_JOYDEVICEREMOVED, SDL_QUIT, \
4343
SDL_JOYBUTTONDOWN, SDL_JOYBUTTONUP, SDL_JOYHATMOTION, SDL_JOYAXISMOTION, \
4444
SDL_GetTicks
@@ -352,6 +352,8 @@ def handle_new_input(e: SDL_Event, axis_norm_value: int = 0) -> bool:
352352
if joystick.SDL_JoystickNumAxes(stick) > 0:
353353
axis_prev_values[joystick.SDL_JoystickInstanceID(stick)] = [0 for x in range(joystick.SDL_JoystickNumAxes(stick))]
354354

355+
# Remove any spurious axis movements reported by SDL during initialization
356+
SDL_FlushEvent(SDL_JOYAXISMOTION);
355357
continue
356358

357359
if event.jdevice.which not in active_devices:

0 commit comments

Comments
 (0)