Re: Python: Usage for Joysticks and External Controllers?

HEY, just in case you are still interested, I added joystick support for pygame aplications on the past.
Basically, you initialize an instance of pygame.joystick.joystick(id), and check the state of a button by myjoystick.get_button(buttonId). for axes, you get the current value with: myjoystick.get_axis(axisId). In this case, it returns a value from -1.0 to 1.0 representing the current state.
of course, checking input this way is not optimal at all, so soon or later you'll need to write your own snipets. My aproach is a getState function that returns a state object with all current controller values for buttons and axes, so I can compare it with a previous joystick state.
I can share some code if someone is interested, but it's not hard to write your own wrapper.
Finally, there should be a lot of other options out there, but hopefully it could help you, at least for experimenting purposes.
Happy codinn.
Edit: I forgot to mention that you can listen for events such as pygame.JOYBUTTONDOWN or pygame.JOYBUTTONUP, etc. Event.button represents the button that has been pressed or released, I think. I am writing this topic from my phone, cannot test code or consult the documentation, but this is the main concept.
I didn't use this last aproach because writing my own button_pressed funtion seemed easier checking and comparing an object representing the joystick state than dealing with different event types, JOYBUTTONDOWN, JOYAXISMOTION, etc.

-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
  • ... AudioGames . net Forum — Developers room : redfox via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Hijacker via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Turret via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : chrisnorman7 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : GrannyCheeseWheel via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : redfox via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Alan via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Alan via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : chrisnorman7 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : GrannyCheeseWheel via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Ethin via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : chrisnorman7 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Ethin via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Ethin via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Ethin via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : chrisnorman7 via Audiogames-reflector

Reply via email to