I am using Builder in standalone PsychoPy 1.80.07 in Windows. I'm trying to figure out how to create a Code Component to receive responses from a Logitech F310 Gamepad. Ideally, I would like to just use the triggers. I do not get any error code when I run the experiment (which is the Stroop keyboard IO demo with the IO keyboard code component code replaced with the below code). It seems to run fine, but it just shows the first trial and waits for a subject response as thought it isn't hearing the gamepad. Also, I am able to run the XInput Gamepad Coder Demo, and everything works just fine. I'm a novice at coding, so any help in pointing out where I've made mistakes would be much appreciated!
Here is what I have in my Code Component:
#Begin Experiment
try:
from psychopy import visual, core
from psychopy.iohub import launchHubServer, EventConstants
from psychopy.data import getDateStr
kwargs={'psychopy_monitor_name':'default','xinput.Gamepad':{}}
io=launchHubServer(**kwargs)
gamepad=io.devices.gamepad
except Exception, e:
import sys
print "!! Error starting ioHub: ",e," Exiting..."
sys.exit(1)
#Begin Routine
response_event=None
trial_start=0
io.clearEvents()
#Each Frame
if frameN == 0:
io.clearEvents('all')
trial_start=core.getTime()
else:
gamepadState=gamepad.getEvents()
for anyState in gamepadState:
if anyState in [u'left_trigger',u'right_trigger']:
response_event=gamepadState
continueRoutine = False
break
#End Routine
trials.addData("trial_start_time", trial_start)
if response_event:
trials.addData("resp.time", response_event.time)
trials.addData("resp.rt", response_event.time-trial_start)
trials.addData("resp.duration", response_event.duration)
trials.addData('resp.keys',response_event.key)
trials.addData('resp.corr', response_event.key.lower()==corrAns)
else:
trials.addData("resp.time",-1.0)
trials.addData("resp.rt", -1.0)
trials.addData("resp.duration", -1.0)
trials.addData('resp.keys','None')
trials.addData('resp.corr', False)
#End Experiment
io.quit()
See Question&Answers more detail:os