Howdy, Stranger!

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

Supported by

Counting keystrokes in Opensesame

Hi! I'm developing an experiment on Opensesame for the first time. I have to show a series of visual stimuli (three images, 60 sec per image) and count how many times the subject presses the spacebar while watching the image for 60 sec. (A text explaining why pressing the button must be shown before). How can I do that and count separately for each image?

I already tried with the graphic interface but I did't reach my goal and unfortunately i can't code with phyton, can someone help me? 😊

Comments

  • edited June 2023

    Hi Silvia,

    it is never to late to learn Python. When you experience that you need to implement something that you can't yet, chances are high that you will need to do so again. So it might be worth the investment. See for example here for Python resources: https://pythontutorials.eu/

    As for your problem, implementing it in Python is the easiest option I think, but you can also get around it, if you do following:

    1. Make a loop/sequence with the sketchpad and a second loop/sequence in it.
    2. In this second loop, set the repeat field to some value that will almost certainly be higher than what any of your participants will respond.
    3. In this second loop, have a keyboard response with the duration set to infinite .
    4. set the run_if field of the second loop to "second_loop_name_time" - "sketchpad_time" < 60000 (the stuff in the brackets must match your variable names, check the logger if you want to know how the variables are called.

    In Python you just need one inline_script:

    images = ['a.png', 'b.png', 'c.png']
    cv = Canvas()
    kb = Keyboard()
    timeout = 60000
    
    for image in images:
        counter = 0
        cv.image(path = exp.pool[image]
        start_time = cv.show()
        while clock_time() - start_time < timeout:
            k, t = kb.get_key()
            if k is not None:
                 counter += 1
        log.write_vars() 
    
    

    Good luck,

    Eduard

    Buy Me A Coffee

  • Thank you so much for your help! I've tried the graphic interface approach but something didn't work, so I tried to copy your python script but it returns a syntax error in line 9, can you help me to fix it, please?

  • Please share your experiment. Screenshots are not as useful to identify the problems.

    Eduard

    Buy Me A Coffee

Sign In or Register to comment.