Keyboard component not saving all key responses

Hi everyone,

I’m trying to save my keyboard responses as reaction time. Here are my outputs:

Here trial type, soundOnset and Trials Condition work as excepted, 0 = standard condition and 1 = oddball condition. However if we look at ReactionTime, it’s saved in the last Dict, however when I ran through my experiment, I pressed my key spacebar after the oddball sound, hence it should be contained within the second Dict. I’ve tried moving the code component incase it was a timing issue, but I haven’t been able to resolve it. Furthermore, when I look at the output from my keyboard component

:

We see there were actually four key presses, not just one.

I’ve attached my code below, it’s within the each frame section of the code component. I created a keyboard component called oddball_resp_Demo. it’s start time should be when a sound onset plays, thus I am measuring the RT from when a sound starts playing.

See below for an image. Does anyone know why this might be occurring?
Thank you in advance!

image

Code which is currently working except for the issue I described above.

‘’’
if oddballClock.getTime() >= thisOnset:

#start keyboard at time of sound onset
#oddball_resp_Demo.start
# it is time to play a tone - let's play one 
Type_of_trial.append(thisTrialType)
Onset_of_sound.append(thisOnset)
Trial_Reaction_time.append(oddball_resp_Demo.rt)





if thisTrialType == 'standard':
    #play standard tone
    standard_tone.volume = 1
    standard_tone.play()
    TrialCond.append(0)
    
   
elif thisTrialType == 'oddball':
    #play oddball tone
    target_tone.volume = 1
    target_tone.play()
    TrialCond.append(1)
    
    

#reset the keyboard clock before next trial

oddball_resp_Demo.clock.reset()

# increase the oddball trial number by one
oddballTrialN += 1




if len(oddballPractice)-1 <= oddballTrialN or oddballClock.getTime() > 300:
    wait(0.5)
    continueRoutine = False
    Demo_trials.finished = True
else:
    # update onset and trial type to reflect new trial number
    thisOnset = oddballPractice[oddballTrialN]['trialOnset']
    thisTrialType = oddballPractice[oddballTrialN]['trialType']
    
#    print('The next trial will be presented at ', thisOnset, 'seconds')
#    print('It will be a ', thisTrialType, 'trial')


  

   

    thisExp.addData("TrialType", Type_of_trial)
    thisExp.addData("soundOnset", Onset_of_sound)
    thisExp.addData('TrialCondition', TrialCond)
    thisExp.addData('ReactionTime', Trial_Reaction_time)
    '''

please could you show us the “Data” tab of your keyboard component? if you have that set to “all keys” it should save the response time of all key presses by default (without need for a code component?)

Could you explain a little more on why you’re currently using this code component rather than builder components ?

Thanks!
Becca

Hi Becca,

I checked the Data Tab, it’s set to collect all keys.

image

The builder is fine to create the keyboard component. The problem I have is the keyboard component was storing reaction time in relation to my visual search task, not my auditory oddball task. I believe I have solved this issue by setting the keyboard duration to the onset of the tones played. The problem I am having is whilst the keyboard component is saving all responses, it doesn’t tell me which condition that response was made under standard or oddball tone.

Thus I wanted to save the RT as a dictionary so I can easily match them up to my dictionary of conditions. However saving RT in a dict however currently isn’t working. I’m wondering if it’s an issue between keyboard onset and keyboard resetting.

ADDITIONAL INFO:

I’ve been doing further testing today.

They keyboard component is capturing the RT fine, however when I print them it only shows a few, AND they are in the wrong order. Output three shows the printed values, whereas output 4 shows the captured values. 0.4295 should be the first printed value, yet it isn’t.

output3
output4

Kind regards,

Rob

For this you probably want to store a list of the standard/oddball onset times right? so that you can cross check the times of the key presses and times of the tones?

Could you show us where you are calling your print statement? the full list of RTs usually wont show untill the end of a routine - so if you try to print on a single frame for example it’s possible it could show only one?

Becca

Hi Becca

With point one, you’re absolutely right. I can save the onset times no problem, it’s more I can save the reaction time, if it’s purely the data generated from my keyboard component, but it isn’t in relation to my sound onset, hence I don’t know which reaction time is for which sound onset.

I’ve attached a print screen of where I have my print statement. What’s interesting is, if I don’t have the code:

react = oddball_resp_Demo.rt

The print statement works on frame and the reaction times look good. Adding in the code doesn’t save it as it should, it’s no longer printing it on frame, and it’s slow, and doesn’t save it on frame, it’s as if it’s late.

This output shows the difference between reaction times I have tried to manually capture, vs the ones captured by my keyboard component.

capturedRT should match oddball_resp_Demo.RT, however it doesn’t. Furthermore, on row 6, in capturedRT it should have a reaction time as it shows space bar was pressed, but it’s not saving the reaction time.

Kind regards,

Rob