import random from openexp.keyboard import keyboard # Inter-stimulus interval ITI = 20 # The number of cycles n_cycles = 20 # Determines whether the canvas list is presented in random order # or sequentially random_order = False # Set-up a keyboard object with a timeout equal to the interval # between the two stimuli my_keyboard = keyboard(exp, timeout=1) # Copy a number of canvases from sketchpads and put them in a list canvas_list = [ self.copy_sketchpad('sketchpad_1'), self.copy_sketchpad('sketchpad_2'), self.copy_sketchpad('sketchpad_3') ] # Start the response interval start_timestamp = self.time() # We are going to keep a list of responses resp_list = [] # Go into a loop where the two canvases are shown in alternation for i in range(n_cycles): # Show the first canvas if random_order: my_canvas = random.choice(canvas_list) else: my_canvas = canvas_list[i % len(canvas_list)] # Show the canvas t1 = my_canvas.show() # Use the get_key() function to sleep and monitor for keypresses # at the same time. while self.time() - t1 < ITI: resp, t2 = my_keyboard.get_key() if resp != None: # If a key was pressed, add it to the list of responses. resp_list.append( (resp, t2) ) # If the response_list is empty, no response was given if len(resp_list) == 0: response = 'timeout' response_time = 0 # Otherwise get the first response from the list else: resp, resp_timestamp = resp_list[0] response = resp response_time = start_timestamp - resp_timestamp # Set the response variables! exp.set('response', resp) exp.set('response_time', response_time) # To maintain feedback variables, see #