1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] How do I utilize the pygame._sdl2.controller module? Does it even exist?

Discussão em 'Python' iniciado por Stack, Setembro 16, 2025.

  1. Stack

    Stack Membro Participativo

    I'm in the throes of producing a game, and with my keyboard controls going well, I decided to start expanding into controller support. Following the documentation, I thought I had initialized pygame.controller and created two controller objects, but the compiler rejects it, saying that the controller module doesn't exist. And checking the auto-completion for pygame., that is absolutely the case; I see the pygame.joystick module, I see a whole bunch of controller events (i.e. CONTROLLER_BUTTON_A and CONTROLLERAXISMOTION, all things listed in pygame._sdl2.controller's documentation), but I see no controller object itself.

    I originally started with pygame.controller, but on closer examination, I changed it to pygame._sdl2.controller, as per the documentation. No success; compiler still throws an error, saying _sdl2 is not an attribute of pygame. I've searched to see if any other developers have been having similar problems, but it almost feels like I'm the first person to ever try to use the module - everyone else seems to use pygame.joystick, with no mention of pygame._sdl2.controller. And I would absolutely do the same; it just seems really convenient to scan for all controller button presses (and releases!) and comparing them to events like CONTROLLER_BUTTON_A.

    So am I just missing something here? Do I need to update SDL2 or something? (Is that even a thing?) Is there a different way to fetch all button presses so I can compare them to the CONTROLLER_BUTTON events? (I know that pygame.joystick has similar methods, they just aren't ABXY specific like pygame._sdl2.controller methods are documented to be.) I'm using what I believe to be the latest version of pygame (2.5.0).

    On closer inspection of the pygame.joystick module, it seems very powerful, and it has mappings for modern controllers, which is useful. Though I'm probably gonna start moving in that direction, I'm still curious about this pygame._sdl2.controller thing; is it just deprecated, or what?

    Continue reading...

Compartilhe esta Página