Menu

Joystick

Gwenn

Joystick

Classes and Methods

cogpy.Joystick()

      Handler class for dealing with Joystick I/O.

      Note: The Joystick class should be used for flight sticks and arcade sticks (anything with a single primary joystick),
      while the Gamepad class should be used for traditional multi-joystick game controllers.

      button( button )

            Trigger-style function--waits until the specified button is pressed on the joystick, then returns.

            When the button is pressed, will set the cogpy.Experiment output attribute to the value of button.

            Note: Joystick.button should only be called in a yield statement within a cogpy.Experiment instance. Will
            return a generator function otherwise.

            The button parameter should be an integer corresponding to one of the buttons on the joystick. The accepted
            values for the button parameter vary among different joysticks.

      changes( axis )

            Trigger-style function--waits until the joystick value for the specified axis changes, then returns.

            When the axis value changes, will set the cogpy.Experiment output attribute to a 2-element tuple with
            the axis parameter and the value of that axis as computed by Joystick.get_axis.

            Note: Joystick.changes should only be called in a yield statement within a cogpy.Experiment instance. Will
            return a generator function otherwise.

            The axis parameter should be one of "x", "y", "z", "u", "v", "povx", or "povy". If the entered axis is not available,
            will raise a RuntimeError.

      get_button( button )

            Returns True if the specified button is currently pressed, False otherwise.

      get_pos( axis )

            Returns an integer value corresponding to the current position of the specified axis.

            Return values range from -100 to 100.

      has_axis( axis )

            Returns True if the joystick has the specified axis, False otherwise.

            Accepted values for the axis parameter are: "x", "y", "z", "u", "v", "povx", and "povy".


Example Usage

import cogpy

class Test(cogpy.Experiment):
    display = cogpy.Display()
    joystick = cogpy.Joystick()

    def start(self):
        print joystick.has_axis("z")
        yield joystick.changes("z")
        print self.output
        print joystick.get_axis("z")
        yield joystick.button(1)
        print joystick.get_button(1)

exp = Test()
exp.run()

Interpreter output:

True
("z",23)
23
True

Related

Wiki: Home

MongoDB Logo MongoDB