[open] Collecting responses during a text display
Hi,
Thanks in advance for any help.
I want to collect keypress responses during a text display screen. I cannot have the text display be set to a keypress time though because I'm doing a scanning experiment and need it to last a certain number of seconds. I see the keypress logger option, but I'm wondering if there's something I have to do to imbed it into the text display option?
Hope this makes sense! This is all quite new to me!
Thanks!
Sarah

Comments
Hi Sarah!
You're very close! You can set your text_display item's duration to 0. After this, put in an inline_script to which - in the run phase - you add the following:
from openexp.keyboard import keyboard # timeout in milliseconds maxtime = 3000 # list of allowed keys allowedkeys = ['return', 'space', 'k', ';', '9', 'right'] # create keyboard object my_keyboard = keyboard(self.experiment, keylist=allowedkeys, timeout=0) # wait for keyboard response or timeout no_timeout = True no_response = True starttime = self.experiment.time() while no_timeout: if no_response: pressed, presstime = my_keyboard.get_key() if pressed: self.experiment.set("response", my_keyboard.to_chr(pressed)) self.experiment.set("response_time", presstime - starttime) no_response = False if self.experiment.time() - starttime >= maxtime: if no_response: self.experiment.set("response", 'timeout') self.experiment.set("response_time", None) no_timeout = FalseThe allowed keys are now set fairly random (the return, 'k', ';' and '9' buttons, as well as the space bar and the right arrow button), but you can edit that any way you want.
Hope this helps! (if not, please just give us a holler)
N.B.: this inline_script will replace the function of a keyboard_response, so you do not have to add a keyboard_response anymore (but do use a logger!).
Thanks Edwin, I'll give it a try. This is my first go at programming anything.
Hi Edwin,
When I insert the script, I get the following error:
Error: Script error Description: Error parsing variable definition: 'set font_family "mono" from openexp.keyboard import keyboard # timeout in milliseconds maxtime = 3000 # list of allowed keys allowedkeys = ['return', 'space', 'k', ';', '9', 'right'] # create keyboard object my_keyboard = keyboard(self.experiment, keylist=allowedkeys, timeout=0) # wait for keyboard response or timeout no_timeout = True no_response = True starttime = self.experiment.time() while no_timeout: if no_response: pressed, presstime = my_keyboard.get_key() if pressed: self.experiment.set("response", my_keyboard.to_chr(pressed)) self.experiment.set("response_time", presstime - starttime) no_response = False if self.experiment.time() - starttime >= maxtime: if no_response: self.experiment.set("response", 'timeout') self.experiment.set("response_time", None) no_timeout = False 'I'm unclear what this means. (Again, I'm not a script person!)
Thank you for any help!
It seems that you have pasted the script into the OpenSesame script that defines an item, rather than a Python inline_script item (for an explanation of the difference, see here).
Is that correct? If so, could you try it again, but this time add a new inline_script item to the experiment, and paste the code into the editor of this item?
Cheers!
Check out SigmundAI.eu for our OpenSesame AI assistant!
Thank you Sebastian!