Typing multi-character responses with keyboard
I'm creating an experiment in OpenSesame where participants need to answer multiplication problems by using their keyboard. However, the keyboard response only registers the first of two digits when the solution is a two-digit number, and also continues to the next trial immediately after typing the first digit. How can I make sure that the program registers the full two-digit keyboard response before continuing to the next trial? Thanks!
Comments
Hi @EJacobs,
In OpenSesame, collecting and appending multiple keyboard responses in the same trial involves using a loop to repeatedly capture keyboard input and then appending these inputs to a list or string.
The simplest way to achieve this is to use a loop containing a sequence containing the keyboard object, to set the loop to repeat a high number of times, to use code within the sequence to append the keys pressed as they get pressed, and to detect when "Enter" is pressed to then set a variable serving as a check that the input is complete, which you check against a certain condition in the "Break if" section of the loop.
In other words, the keyboard object should run in a loop within the trial's loop (i.e., nested loop) and you'd use code to track what is being pressed and define the condition under which that nested loop breaks so that the trial continues.
Alternatively, if you'd rather use pure Python code and avoid creating nested loops, using the keyboatrd object etc., you can use the method described here: https://forum.cogsci.nl/discussion/31/solved-multi-character-keyboard-response-or-simultaneous-sketchpad-and-text-input
Hope this helps,
Fabrice.
Hi Fabrice,
Thank you for your help! I managed to create a nested loop, so I'm now able to type multiple keyboard responses. However, I'm still struggling with the code within the sequence to make sure all of the pressed keys are detected/registered, as well as using code to break the keyboard loop when "enter" is pressed. Could you maybe provide me with a code that I can use for this? Thank you!
I also have another question that is related to this. I want the participants to be able to see the answer that they're typing. Is this possible? If yes, how can I do this?
Hi Fabrice,
I've worked on it a little bit more: I've used code and managed to make the nested loop break when 'return' is pressed and the participants are also able to see what they're typing, so this is solved. However, in the log file only the last keypress is registered (which is 'return') and, therefore, the log file always says the participant's answer was incorrect. I need the experiment to log the full response before return is pressed and this response needs to be checked against my variable 'Correct_Response' to determine the accuracy of the response. Could you help me with this?
Hi,
I don't know how your experiment looks like, but if the logger is only logging the last response, it usually helps, to move it inside the nested loops one level, so that it is called more often, and not just once in the end. Do you know what I mean?
Eduard
That helped, thank you! It is logging all off the keyboard responses now. However, the var.accuracy is still showing the responses as incorrect, because it is logging each keyboard response separately. For example, if the correct response is 12, the participant has to type '1' '2' and 'return', which is logged as an incorrect response, because the program checks all of the keyboard presses separately against the correct_response (which is 12). Does that make sense? Is there a way to solve this?
I just read your initial post, and I am surprised you haven't tried the text_input form. It was added to Opensesame for exactly this reason. So, no need to nest loops or anything alike. Just use a text input.
Eduard