Howdy, Stranger!

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

Supported by

Visual Looking Preference Paradigm

Has anyone used OpenSesame to develop a Preferential Looking experiment such as the Fagan Test of Infant Intelligence? I couldn't find it in the list of standard tests, but please let me know if I missed it.

Specifically, I'd like to record the latency and duration of all keypresses from two keys while the stimulus is presented. I have some experience creating OpenSesame experiments from the GUI, and I'm ready to add in some inline code as needed.

Any help is greatly appreciated!

Julie

Comments

  • Update: I should have been more specific in my previous post. I can record the keys and timing of keypresses during stimulus presentation. After displaying a sketchpad (duration = 0), I added the following inline code:

    my_keyboard = Keyboard()
    my_keyboard.keylist = [u'left', u'right']

    while True:
    keydown1, timedown1 = my_keyboard.get_key()
    keyup1, timeup1 = my_keyboard.get_key_release()
    if ((timeup1 - timedown1) >= 5000:
    break

    var.look_direction1 = keydown1
    var.look_length1 = timeup1 - timedown1

    This is followed by a sampler item.

    My remaining questions are:
    1) How can I iterate this, such that for each keypress I can record the key and duration of the keypress until the summed time either key is pressed totals exactly X ms, where X = [block loop variable] instead of 5000? As written now, the key must be released before the iteration breaks, but I'd like it to break regardless of whether the key is up or down when the accumulated keypress time occurs.
    2) The sampler cues that this portion of trial is over. Is there any reason to include that here in the inline code instead?

    I'm happy to provide more information if needed.

    Thank you for your patience with my inexperience!

  • edited August 20

    Hello,

    2) The sampler cues that this portion of trial is over. Is there any reason to include that here in the inline code instead?

    I don't understand what you mean, but generally it is quite easy to include the sampler in an inline_script. Given the setup of your code above, it is probably even necessary to do so. Check out this part of the documentation to learn how to use samplers in inline_scripts.

    1)

    my_keyboard = Keyboard(timeout=0)
    my_keyboard.keylist = [u'left', u'right']
    
    var.totalDur = 0 # initialize a counter for the total down time (across key presses)
    start_time = clock.time() # init stopwatch
    while True: # first while loop takes care of multiple key presses
        if ((clock.time() - start_time) >= var.block_loop_variable: 
                break       
        while True: # second while loop takes care of waiting for the first down key
            keydown1, timedown1 = my_keyboard.get_key()
            # only if a key was pressed, check whether it was released already
            if keydown1 != None:
                while True: # third while loop waits for first key up
                    if ((clock.time() - start_time) >= var.block_loop_variable: 
                        break
                    keyup1, timeup1 = my_keyboard.get_key_release()
                    if keyup1 != None:     
                        var.curDur = timeup1 - timedown1
                        var.totalDur += var.curDur
                        break
                if var.totalDur >= var.block_loop_variable: # however you called it in the loop table
                    break
             if ((clock.time() - start_time) >= var.block_loop_variable: 
                    break       
    
    var.look_direction1 = keydown1
    var.look_length1 = timeup1 - timedown1
    

    Not sure whether this code is exactly what you need, but I think it should you get started on your problem. They key trick is to set the timeout of your keyboard to 0, so that the experiment doesn't sleep during that time and still keeps track of the elapsed time.

    Let us know if you need further help.

    Eduard

  • Thank you very, very much, Eduard. Your response has definitely pushed me in the right direction. I'll be sure to let you know when I reach the solution (or if I need more help!).

    Julie

  • Thank you again for your help, Eduard. I've used the code you sent to move forward, but I was unable to successfully record the duration of each keypress. The following inline script nearly works. I can now correctly measure the total look duration at any point in a trial, and move on to the next part of the experiment once the criterion for look duration is reached (I use 5000 ms here just to make things simpler).

    My Remaining Question:
    Why does the log only display the key name and RT of the first KEYDOWN event, but no subsequent KEYUP or KEYDOWN events? The program itself seems to run correctly--I can make multiple keypresses until the total keypress time = 5000 ms (confirmed with my own stopwatch).

Sign In or Register to comment.