I’m a beginner on psychopy and i’m following several tutorial. But I have a question today. From the builder, how can I include a text response, that is the stimuli appear (that’s ok) and participants need to write some text and click on “space” or “enter” to go to next trial ?
Oh great, it is perfect ! Thank you for your answer !
I have a last question. I use the textbox, but how do for that participants can press on “space” or “enter” or an other keyboard letter to validate the answer and go to the next stimulus ?
You pick up on a good question, this is currently something being ironed out in the textBox component. For me so far I have added a keyboard component to the routine that force ends the routine, but that means that in the keylist of this component you need to make sure to list keys that the participant would not use whilst typing (this is tricky because they could even use the arrow keys to move the cursor in the text box). A better solution suggested by one of the team today was to use a mouse component to end the routine, and allow “any click” to force end the routine.
The trade off is that participants might be slower to register a response after typing with a mouse click compared with a keyboard keypress - so it depends if response time is important for your study.
I use the mouse component to end the routine, because response time is not important in my study. Thus, participants write their answers, I have added a text to component (“click to go to the next trial”), and any click forces the end the routine.
Is there any way to make sure participants made a typed response before ending the routine? I’ve an experiment with a task asking for a typed response, but had noticed that participants can skip answering many questions, i.e. not typing any thing, but simply ending the routine using a keyboard component ‘Enter’.
Yes there is! But it involves some code components. You essentially need to check if the textbox currently contains anything and then end the current routine only if it does contain something.
I first make a function (in the before experiment tab so that it works online) to check if the textbox is what I would class as empty (has only a space or nothing):
def checkEmpty(text):
if text == " " or text == "":
return True
else:
return False
Then in the each frame tab I use a code component to watch for key presses and submit:
# watch for key presses
keys = event.getKeys()
if 'return' in keys:
# do not show a new line break in the typed response
textbox.text = textbox.text[:-1]
# check if the response is empty and only allow the routine to end if something has been typed
continueRoutine = checkEmpty(textbox.text)
# clear the keyboard keys and watch for a new response
event.clearEvents('keyboard')
Thank you for your response. I understand that thses codes are used with the text.box function. Unfornately I didn’t use this function but I the following codes that work well with me except for enforcing response.
actualKeys = event.getKeys()
n = len(actualKeys)
i = 0
while i < n:
if actualKeys[i] == 'return':
continueRoutine = False
break
elif actualKeys[i] == 'backspace':
inputText3 = inputText3[:-1] # lose the final character
i = i + 1
elif actualKeys[i] == 'space':
inputText3 += ' '
i = i + 1
elif actualKeys[i] in ['minus', '-', 'num_subtract', 'Minus', 'slash']:
inputText3 += '-'
i = i + 1
elif actualKeys[i] in ['lshift', 'rshift', 'SHIFT']:
shift_flag = True
i = i + 1
else:
if len(actualKeys[i]) == 1:
if shift_flag:
inputText3 += actualKeys[i].upper()
shift_flag = False
else:
inputText3 += actualKeys[i]
i = i + 1
I’m not quite sure what changes should I make to these codes to end up with the same results, i.e. having at least 3 input characters to end the routine.
I’ve tried this and it works, participants now cannot move to the next question unless they input at least 1 character. Do you have any idea how to make it to ‘at least 3 charachters’ to be able to proceed?
I’m trying to run the same experiment using another language, namely Arabic which follows right to left language style. The same coding doesn’t work with me. the screen displays only English letters even when using Arabic keyboard. I tried using the textbox instead of the coding, half of the problem solved but I still got the Arabic letters written from left to right even when I changed the style to Arabic and RTL style. Do you know any way to amend the codes so that I get it right, with Arabic letters from right to left?
I am also trying to allow people to continue only if they give input.
This code seems to work locally in python but not online in JS. Is there something else that needs to be done to get this to work: Enter just changes the line.