Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from openexp.keyboard import keyboard
- # Inter-stimulus interval
- ITI = 50
- # The number of cycles
- n_cycles = 10
- # Set-up a keyboard object with a timeout equal to the interval
- # between the two stimuli
- my_keyboard = keyboard(exp, timeout=ITI)
- # Copy the canvas from two sketchpads. You will show these sketchpads
- # here using inline_script, so in the experiment you probably want to
- # 'hide' them by setting the run-if statement to 'never'. Of course, you
- # can also canvases using inline script, instead of copying them from a
- # sketchpad.
- canvas_1 = self.copy_sketchpad('sketchpad_1')
- canvas_2 = self.copy_sketchpad('sketchpad_2')
- # 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
- t1 = canvas_1.show()
- # Use the get_key() function to sleep and monitor for keypresses
- # at the same time.
- 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) )
- # And also sleep for the remaining time of the ITI
- self.sleep(ITI - t2 + t1)
- # Same principle for the second canvas
- t1 = canvas_2.show()
- resp, t2 = my_keyboard.get_key()
- if resp != None:
- resp_list.append( (resp, t2) )
- self.sleep(ITI - t2 + t1)
- # 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
- # <http://osdoc.cogsci.nl/usage/giving-feedback-to-participants/#inline-script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement