Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

[solved] How do I collect the keyboard_response after a stimulus disappears?

edited January 2014 in OpenSesame

Hi, Sebastiaan. I'm jongsup, your Korean colleague who is teaching Psycholinguistics using OpenSesame at a Korean university. Hope you remember the e-mail correspondence we had last winter.

Here's my question. I want to present a target stimulus for 500ms. That is, the target stimulus should disappear in 500ms. But I want to set the timeout for keyboard_response to 2000ms. That is, the response should be recorded for 2000ms (even after the target stimulus goes away).

How can I achieve this? Can you suggest me any useful inline script for this? It seems that I need something more than the 'self.sleep()' script.

Thanks in advance for your help and efforts.

From JS

Comments

  • edited August 2013

    Hi Jongsup,

    Yes, of course I remember! Great to heard that you're actually using it now.

    Below is a quite elaborate inline script that should do what you need. Basically, it collects a response first with a timeout of 500ms. If no response is collected during that time, the display is blanked and a response is collected again for 1500ms, giving a total timeout of 2000ms. It also maintains feedback variables, etc., which is actually most of the script. Importantly, the script assumes that it is preceded my a sketchpad called my_sketchpad with a 0ms duration. So you can just present the target stimulus on a regular sketchpad.

    Hope this helps!

    Cheers,
    Sebastiaan

    # This code snippet assumes that it is
    # preceded my a sketchpad called 'my_sketchpad'
    # with a 0 duration.
    #
    # The code below collects a response for a
    # maximum of 2000ms. After 500ms the canvas
    # is blanked.
    
    from openexp.canvas import canvas
    from openexp.keyboard import keyboard
    
    # Uncomment for 0.25 or earlier
    # exp = self.experiment
    
    # Some settings
    timeout1 = 500
    timeout2 = 2000
    allowed_keys = ['z', 'm']
    
    # Create keyboard and canvas objects
    my_keyboard = keyboard(exp, keylist=allowed_keys)
    my_blank_canvas = canvas(exp)
    
    # Set actual timeout. By taking into account
    # the current time and the timestamp of
    # my_sketchpad we reduce temporal jitter
    timeout = timeout1  - self.time() + exp.get('time_my_sketchpad')
    
    # Collect a keyboard response with a stim_dur timeout
    # and show a blank canvas afterwards
    resp, time = my_keyboard.get_key(timeout=timeout)
    my_blank_canvas.show()
    
    # If no response has been given, we wait for another
    # post_stim_dur milliseconds
    if resp == None:
        timeout = timeout2 - self.time() + exp.get('time_my_sketchpad')
        resp, time = my_keyboard.get_key(timeout=timeout)
    
    # Set response, correct, and response time
    response_time = time - self.get('time_my_sketchpad')
    response = my_keyboard.to_chr(resp)
    if not self.has('correct_response'):
        correct = 'undefined'
    elif response == self.get('correct_response'):
        correct = 1
    else:
        correct = 0
    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
    
  • edited May 2012

    Goodness! How can I express my deepest gratitude to you, Sebastiaan? I will definitely test this inline script with my students, and may ask you further questions. At the moment, I want to let you know that I have taught more than 80 students how to use OpenSesame this semester here in Korea. We all admire your help and achievement!

    JS

Sign In or Register to comment.