Howdy, Stranger!

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

Supported by

Using spacebar to accept and close a "text_input" form


I'm using the great new option to measure key release (Thank you Sebastiaan and team! :) ).
I have a slide where participants need to release the sapcebar to move to a text_input form where they write
their response.

Right now to accept and close the form, the 'return' key should be pressed.
Is there a way (preferably with as less coding as possible) to use the spacebar instead of return?



  • and one more thing: I need the spacebar to be pressed when the target slide appears.
    Is there a way to define "run if spacebar is pressed"?

  • Hi Tali,

    Is there a way to define "run if spacebar is pressed"?

    in a run if field, probably not, but in an inline_script you could implement a while loop that runs until a key has been pressed, and while it has not been released. Unfortunately, this is not exactly "with as less coding as possible"

    With the other question, I can't really help you. maybe you can Monkey patch the form execution function so that accepts also space presses, but for that you need to understand how Opensesame runs forms (better than I do). Maybe @sebastiaan has a nifty solution for that?


  • Thanks for responding Eduard.... This is one of these times when I wish I had some computer science knowledge :/

    What if I design a form by myself? can I use anything other than enter ?

  • Hi,

    If you are willing to use a mouse, you can disable the return key, and use a next button instead?

  • The only real solution that I can think of is to monkey patch the Keyboard class such that space keys are remapped to return keys. The script below does this, using a so-called decorator around get_key(). This will affect all key presses though!

    from openexp._keyboard.legacy import Legacy
    def remap_space(get_key):
        """A decorator for the original Keyboard.get_key() to remap the space key
        to a return.
        def inner(self, *args, **kwargs):
            key, time = get_key(self, *args, **kwargs)
            if key == 'space':
                key = 'return'
            return key, time
        return inner
    Legacy.get_key = remap_space(Legacy.get_key)

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

  • Thanks! I'll try this

Sign In or Register to comment.