Recording Keyboard Responses from Stimulus Onset while Keeping Stimuli on Screen
I've been having some trouble with an experiment in which I want to present a target briefly (100ms) and then fixation for 1500 ms and record responses from the onset of the target. I would like the timing to be the same for everyone, so that the target or the fixation screen remain up even after a key is pressed. From reading other discussions on the forum, it seemed easiest to do this in an inline script, but two problems arise with the script I'm currently running
1 - I've tried to keep the stimuli on screen by using the self.sleep function; however, it looks like my target still disappears as soon as something is pressed (I've experimented with long target duration to be sure)
2 - It doesn't look like responses are being recorded, which makes me think that there is something wrong with how I am setting up the keyboard.
I'm including the code I've used (similar to what is posted on another discussion). Any thoughts as to what may be going on here?
Note: my_target_canvas and my_fix_canvas are prepared elsewhere. Also, most variable (e.g. tar_present_time and Correct_resp are specified elsewhere. Of note could be that the variable Correct_resp is specified within the loop.
`from openexp.canvas import canvas
from openexp.keyboard import keyboard
#settings self.experiment.set("timeout1",self.get("tar_present_time")) self.experiment.set("timeout2",self.get("keyboard2_time")) #create keyboard my_keyboard = keyboard(exp, keylist=['l','k']) #set actual timout taking into account current time and timestamp of target #sketchpad timeout = self.get("timeout1")-self.time()+exp.get('time_target') #Collect a keyboard response with tar duration timeount resp, time = my_keyboard.get_key(timeout=timeout) if resp!= None: my_target_canvas.show() response_time = time - self.get('time_target') response = my_keyboard.to_chr(resp) if response == self.get('Correct_resp'): correct = 1 else: correct = 0 self.experiment.set("tar_sleep",self.get("timeout1")-self.get("response_time")) self.sleep(self.get("tar_sleep")) my_fix_canvas.show() self.sleep(self.get("timeout2")) #if no response has been given, wait another duration with fixation screen if resp == None: my_fix_canvas.show() timeout = self.get("timeout2") - self.time() + exp.get('time_target') resp, time = my_keyboard.get_key(timeout=timeout) response_time = time - self.get('time_target') response = my_keyboard.to_chr(resp) if response == self.get('Correct_resp'): correct = 1 else: correct = 0 self.experiment.set("fix_sleep",self.get("timeout2")-self.get("response_time")) self.sleep(self.get("fix_sleep")) #set experimental variables exp.set('response_time', response_time) exp.set('response', response) exp.set('correct', correct) # Maintain feedback variables. This ensures that # you can use the feedback item as usual exp.total_responses += 1 if correct: exp.total_correct += 1 exp.total_response_time += response_time exp.acc = 100. * exp.total_correct / exp.total_responses exp.avg_rt = exp.total_response_time / exp.total_responses exp.accuracy = exp.acc exp.average_response_time = exp.avg_rt`
Thank you for your time and and any assistance you can provide!!