cogpy.Gamepad()
Handler class for dealing with Gamepad I/O.
Compatible with all controllers that use the XInput system (most PC & Xbox 360 controllers).
Note: The Gamepad class should be used for traditional multi-joystick game controllers, while the Joystick class
should be used for flight sticks and arcade sticks.
button( button )
Trigger-style function: waits until the specified button is pressed on the gamepad, then returns.
When the button is pressed, will set the cogpy.Experiment output attribute to the value of button.
Note: Gamepad.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 one of the gamepad button constants (listed below).
changes( axis )
Trigger-style function: waits until the gamepad 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 Gamepad.get_axis.
Note: Gamepad.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 gamepad has the specified axis, False otherwise.
Accepted values for the axis parameter are: "x", "y", "z", "u", "v", "povx", and "povy".
Buttons:
cogpy.GPD_Acogpy.GPD_Bcogpy.GPD_Xcogpy.GPD_Ycogpy.GPD_L: Also known as LB.cogpy.GPD_R: Also known as RB.cogpy.GPD_BACKcogpy.GPD_STARTcogpy.GPD_LEFT_JOY: Not available on all controllers.cogpy.GPD_RIGHT_JOY: Not available on all controllers.import cogpy
class Test(cogpy.Experiment):
display = cogpy.Display()
gamepad = cogpy.Gamepad()
def start(self):
print gamepad.has_axis("z")
yield gamepad.changes("z")
print self.output
print gamepad.get_axis("z")
yield gamepad.button(cogpy.GPD_A)
print gamepad.get_button(cogpy.GPD_A)
exp = Test()
exp.run()
Interpreter output:
True
("z",23)
23
True