Howdy, Stranger!

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

Supported by

[solved] double space bar

edited October 2013 in OpenSesame


in some stage of my experiment the responses can be either 1/2 space bar press
I want that the sketchpad will stay on screen to a defined time out

  1. how do I collect multiple space-bar responses
  2. how do I see the responses in the logger

the only discussion I found was:
but it is'nt really what I need




  • edited March 2013

    Hi Dror,

    Sure, that's certainly possible. You'll need a little bit of Python inline scripting for this.

    More specifically, you could continuously pull keyboard responses (with the timeout of the keyboard_response item set to zero) until a certain time has passed (or, for example, until the participant pressed twice). After this interval, your experiment should advance to the next item (e.g. a feedback item or a logger item). During the response interval, you simply count how often the spacebar was pressed and then set this new variable with the experiment function exp.set() so that it will be available in the logger item.

    The following Python code should give you an idea of how to achieve this. Make sure you put it in the Run phase tab of an inline_script item that is appended to your trial sequence in the same way you would normally append your keyboard_response item (which you don't need anymore). So, for example, after stimulus presentation but before a feedback or logger item.

    # Determine the timeout in ms:
    timeout = 3000
    # Create keyboard_response item:
    from openexp.keyboard import keyboard
    my_keyboard = keyboard(exp, keylist=['space'], timeout = 0)
    # Determine the timestamp of the start of the response
    # interval:
    start_time = self.time()
    # Give the number of spacebar presses a starting
    # value, namely 0.
    nPresses = 0
    # Collect keyboard response until 3000 ms (or whatever
    # you set the timeout to) passed:
    while True:
        # Get new timestamp:
        current_time = self.time()
        # Continue only if the duration is still
        # smaller than timeout:
        if current_time - start_time < timeout:
            # Collect keyboard response:
            key, end_time = my_keyboard.get_key()
            # Add to the number of presses if response was not 
            # 'None' (meaning no key was pressed):
            if key != None:
                nPresses +=1
            # You could advance to the next part of your 
            # experiment as soon as space has been pressed twice.
            # If you want to keep pulling keyboard responses until
            # the timeout, even if participants already pressed
            # twice, simply remove the two following lines.
            if nPresses >= 2:
        # If (more than) 3000 ms have passed, advance to the 
        # next part of your experiment:
    # Set the number of spacebar presses for future use in the 
    # user interface (notably, the logger item). After doing so,
    # you will find :
    self.experiment.set('nPresses', nPresses)

    For more information about keyboard functions via Python inline code, see:

    An example experiment can be downloaded here (save with the extension '.opensesame').

    Does this help?



  • edited 9:08AM

    hi Lotje
    the inline code works like a charm - that's exactly what I needed!

    one further question - I have in every trail 2 responses, one after a sketchpad and another one after a second scratchpad, do I need to use 2 different loggers/one in the end of each trail or 2 loggers that are the same loogers?

    thank's for the quick and very helpful replay

  • edited March 2013

    Hi Dror,

    You're welcome! I'm glad to hear it's working as desired! :)

    Luckily, if you have multiple response items (for example, two keyboard_response items) you don't have to worry about logging their respective output variables separately yourself. OpenSesame takes care of this by storing them in separate variables (i.e. separate column headers in your output file) automatically. So, simply appending one logger item at the very end of your trial sequence is enough.

    More specifically, the given response, as well as it's correctness and response time, collected by a keyboard_response item named 'keyboard_response1' are stored by the following variables, respectively:

    • response_keyboard_response1 (contains the given key press, e.g. a)
    • correct_keyboard_response1 (contains the correctness (0 or 1) of the response)
    • response_time_keyboard_response1 (contains the response time in ms., e.g. 577)

    Therefore, you will always be able to dissociate those output variables from the ones collected by a keyboard_response item named 'keyboard_response2' (for which the variables are obviously named 'response_keyboard_response2', etc.).

    The usually-used variables 'response', 'correct', and 'response_time' always represent the most-recently collected variables. Therefore, in the current example, in the output file those will always be identical to the variables collected by 'keyboard_response2'.

    Does this make sense?

    I uploaded a simple example experiment here (download, change the extension from .txt into .opensesame, and open as normally):

    Don't hesitate to post any further questions!



  • Hello,

    I'm very sorry if I step in between, but I really need help and my question is not so far correlated with the topics you discussed.

    I'm trying to implement an Intentional Binding paradigm in which a clock rotates and the participant's task is to judge when a critical event (tone/keypress) occurs.
    Everything works when the participant is only one, but I need to turn it in a "social" version in which two participants press two different space bars: in one condition they press whenever they want, in the other one it is established (before starting the experiment) who will press the spacebar first ("the initiator") and who will do it for second (the "responder").

    May I know how to get inputs from different keyboards and then to find them into the logger?
    Any help would be really appreciated!!

    Thanks in advance,

  • Hi Cecilia,

    You can connect multiple keyboards to one computer, so that's no problem. Then, to be able to tell who pressed which key, I would have them press different keys (on different keyboards), rather than both press the spacebar. For example, the initiator could press the left arrow key, and the responder could press the right arrow key.


    There's much bigger issues in the world, I know. But I first have to take care of the world I know.

  • Hi Sebastiaan,

    thank you for the reply and apologies for my mess.
    I was able to set multiple keys (specifically, "spacebar" and letter "A") but now I'm in a new trouble.
    I created three different sketchpads, and I'd want to display:

    • the first one only when the spacebar key is pressed first
    • the second one only when the A key is pressed first
    • the third one if spacebar and A are pressed together.

    Is there a way? Can you help me?


  • Hi Cecilia,

    Here's what you could do:

    • Have two keyboard_response items in a row, let's call them kb1 and kb2.
    • Then you can use run-if statements to determine which key was pressed first, e.g. [response_kb1] = a and [response_kb2] = space
    • Keys cannot be pressed simultaneously, but if they are almost pressed simultaneously then the response time on kb2 will be very low, so you can check this again with a run-if statement: [response_time_kb2] < 100


    There's much bigger issues in the world, I know. But I first have to take care of the world I know.

Sign In or Register to comment.