py-sdl / py-sdl2

Python ctypes wrapper around SDL2
Other
303 stars 49 forks source link

sdl2.SDL_Event.type reporting unexpected values #211

Closed sujaldev closed 2 years ago

sujaldev commented 2 years ago

What doesn't work? I am using PySDL2 and skia-python to create a window and in my event loop I am getting completely different values than expected, SDL_QUIT is still 0x100 but events like mouse click, scroll are being registered as SDL_KEYMAPCHANGED or 0x304

How To Reproduce This is my event loop

import sdl2 as sdl
from ctypes import byref as pointer

def sdl_event_loop():
    event = sdl.SDL_Event()
    running = True

    while running:
        event_pointer = pointer(event)
        pending_events = sdl.SDL_PollEvent(event_pointer)
        while pending_events:

            # QUIT HANDLER
            if event.type == sdl.SDL_QUIT:
                running = False
                sdl.SDL_Quit()
                break

            # UPDATE PENDING EVENTS
            pending_events = sdl.SDL_PollEvent(event_pointer)
        sdl.SDL_WaitEvent(event_pointer)

If necessary the entire code is present here

Platform:

sujaldev commented 2 years ago

Weirdly If I click on the window while moving the mouse SDL_MOUSEBUTTONUP is registered correctly.

sujaldev commented 2 years ago

Nvm I figured out the problem.