onJoyHatMotion()

Method that is called when the hat of any connected joysticks changes position. Modern joysticks usually have three analog axis, a hat (digital joystick) and anything from four buttons upwards. This event handler method is fired in the world. Joysticks are automatically initialized when Slut starts.

class Atlantis(World):
    def onJoyHatMotion(self, event):
    	pass
  • event.joy ... joystick number, an integer, starting with 0 for the first joystick
  • event.hat ... a list of two values representing the x and y position of the hat.
    • (0, 0) ... center position
    • (0, -1) ... center, down
    • (0, 1) ... center, up
    • (1, 0) ... right, center
    • (-1, 0) ... left, center
    • (1, 1) ... right, up
    • (-1, -1) ... left, down
    • ...

Relevant examples: joystick.py

In Context

class Atlantis(World):
    def onSetup(self):
        self.name = "Joy"

    def onJoyHatMotion(self, event):
    	print 'Joystick Hat changed position.'
    	print 'Joystick that has fired the event:', event.joy
    	print 'Current hat position:', event.hat
Initiated by Stephan Hechenberger
Thanks to CADRE's 103