I want to programm a dual task and collect the reaction times. My problem is that the function is only returning 666 as buttonR1Code and buttonR2Code although I hit ‘x’ or ‘y’ and ‘,’ or ‘.’. 666 should only be given if no response was collected. How can I fix this? Any suggestions?
I’m using PsychoPy3, Coder, OS Win 10 (64-Bit).
def StimPresent(a_soa, b_s1, c_s2):
"""
Function StimPresent(a, b, c) presents stimulus_1 (b) for SOA ((a) number of frames),
then it adds stimulus_2 (d) and shows both for max 60 frames
and returns time of stimulus onset (tim)
"""
kbR1 = keyboard.Keyboard()
kbR2 = keyboard.Keyboard()
allkeys = 0
while allkeys < 2:
if event.getKeys(keyList='escape'):
myWin.close()
core.quit()
for frameN in range(a_soa):
b_s1.draw()
fixation.draw()
if frameN == 0: # RT S1 starting immediately after flip
onsetS1 = RT1.getTime()
kbR1.clock.reset()
keyR1 = kbR1.getKeys(['y', 'x'], waitRelease=True)
if keyR1 == 'y':
buttonR1 = 55
allkeys += 1
buttonR1Iden = keyR1.name
buttonR1Dur = keyR1.duration
theRT1 = keyR1.rt
elif keyR1 == 'x':
buttonR1 = 44
allkeys += 1
buttonR1Iden = keyR1.name
buttonR1Dur = keyR1.duration
theRT1 = keyR1.rt
myWin.flip()
for frameN in range(a_soa, (a_soa+60)):
b_s1.draw()
fixation.draw()
c_s2.draw()
if frameN == (a_soa+1):
onsetS2 = RT2.getTime() #RT S2 starting immediately after soa flip
kbR2.clock.reset()
keyR1 = kbR1.getKeys(['y', 'x'], waitRelease=True)
keyR2 = kbR2.getKeys(['.', ','], waitRelease=True)
if allkeys == 0:
if keyR1 == 'y':
buttonR1 = 55
allkeys += 1
buttonR1Iden = keyR1.name
buttonR1Dur = keyR1.duration
theRT1 = keyR1.rt
elif keyR1 == 'x':
buttonR1 = 44
allkeys += 1
buttonR1Iden = keyR1.name
buttonR1Dur = keyR1.duration
theRT1 = keyR1.rt
if allkeys == 1:
if kbR2 == '.':
buttonR2 = 55
allkeys += 1
buttonR2Iden = kbR2.name
buttonR2Dur = kbR2.duration
theRT2 = kbR2.rt
elif kbR2 == ',':
buttonR2 = 44
allkeys += 1
buttonR2Iden = kbR2.name
buttonR2Dur = kbR2.duration
theRT2 = kbR2.rt
myWin.flip()
for frameN in range((a_soa+60), 300):
fixation.draw()
deadlineS1 = 210
deadlineS2 = 210
keyR1 = kbR1.getKeys(['y', 'x'], waitRelease=True)
keyR2 = kbR2.getKeys(['.', ','], waitRelease=True)
if allkeys == 0:
if keyR1 == 'y':
buttonR1 = 55
allkeys += 1
buttonR1Iden = keyR1.name
buttonR1Dur = keyR1.duration
theRT1 = keyR1.rt
elif keyR1 == 'x':
buttonR1 = 44
allkeys += 1
buttonR1Iden = keyR1.name
buttonR1Dur = keyR1.duration
theRT1 = keyR1.rt
elif frameN > deadlineS1:
buttonR1 = 666
allkeys += 1
buttonR1Iden = 'NaN'
buttonR1Dur = 'NaN'
theRT1 = 'NaN'
if allkeys == 1:
if kbR2 == '.'
buttonR2 = 55
allkeys += 1
buttonR2Iden = kbR2.name
buttonR2Dur = kbR2.duration
theRT2 = kbR2.rt
elif kbR2 == ',':
buttonR2 = 44
allkeys += 1
buttonR2Iden = kbR2.name
buttonR2Dur = kbR2.duration
theRT2 = kbR2.rt
elif frameN > deadlineS2:
buttonR2 = 666
allkeys += 1
buttonR2Iden = 'NaN'
buttonR2Dur = 'NaN'
theRT2 = 'NaN'
myWin.flip()
return [b_s1, onsetS1, buttonR1, buttonR1Iden, buttonR1Dur, theRT1, c_s2, onsetS2, buttonR1, buttonR1Iden, buttonR1Dur, theRT2, a_soa]
Thank you!