If this template helps then use it. If not then just delete and start from scratch.
OS (e.g. Win10): MacOS Big Sur PsychoPy version (e.g. 1.84.x): 2020.2.10
**What are you trying to achieve?: I would like to present an image and a sound after a participant presses a certain number of keys on the left side of the keyboard. For example, a participant will be given a task to write in a textbox freely, and if they type a sentence that contains 5 keys from the left side of the keyboard, then the image and sound would occur.
**What did you try to make it work?: I tried using a keyboard component and allowing all letters and storing only the left side of the keyboard letters as correct.
**What specifically went wrong when you tried that?: I still do not know how to set up the image and sound to present based on this
Sounds like you want to use a textbox component and then check the text from the textbox component at the end of the routine using a code component. Something like:
left_letters = ['a', 's', 'q', 'w']# and so on
pointcount = 0
for letter in left_letters:
if letter in mytextbox.text:
pointcount += 1
if pointcount > 5: # where 5 is the minimum number of letters from the list needed for the reward
nextRoutineNreps = 1
else:
nextRoutineNreps = 0
Then add a seperate routine where your image is presented and put a loop around it. in the nReps field of the loop write nextRoutineNreps and the routine will be shown if the number of points is met and skipped otherwise.
I might be wrong but my reading of the question is that they probably want the feedback as soon as the fifth target key is pressed rather than after the response is submitted.
If that is the case then use the same code component in the each frame tab with a small edit:
nextRoutineNreps = 0
left_letters = ['a', 's', 'q', 'w']# and so on
pointcount = 0
for letter in mytextbox.text:
if letter in mytextbox.text:
pointcount += 1
if pointcount >= 5: # where 5 is the minimum number of letters from the list needed for the reward
nextRoutineNreps = 1
continueRoutine = False # end the routine when the 5 target keys have been pressed
I don’t know how a trial would end though then if a the target keys were not pressed/an answer was not submitted.
We would like the feedback to occur after they press enter to send their message and end the routine. I put the code you wrote in the end routine tab of a code component, but nothing happens. I used the editable text box component, do I need to use the older text box?
I ended up using the old textbox component and adding code to display the text based on the keys the participant presses. I then used your code and I was able to get it to work! Thank you so much for your time!