Howdy, Stranger!

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

Supported by

[solved] Keyboard Arrows for Selection

edited December 2015 in OpenSesame

I'm trying to design a paradigm where a participant needs to rate a stimulus from a range of 1-5. This would be easy if it wasn't an fMRI, and as the case is such, I can't use mouse clicks. (We don't have an MRI compatible mouse)

A previous paradigm coded on E-Prime made use of a keyboard with 4 buttons. 2 of them were used to toggle left and right (to select options 1-5) and one key was used as a 'select' option.

I've seen the forms and the questionnaire templates, but all of them rely on single button/mouse clicks. How would I be able to build my desired kind of a paradigm? I'm not too familiar with Python either.


  • edited December 2015

    Hi Jacob,

    This will indeed require a bit of Python coding, but nothing terribly complicated. Below you see an example of how you can adjust a 5-point scale with left/ right key presses, and accept by pressing space. The logic is explained in the code comments. You'll probably need to modify it a bit for your purpose, but it should get you started!

    See also:


    # For OpenSesame >= 3.0
    # Create a keyboard and canvas object
    cnv = canvas()
    kb = keyboard(keylist=['left', 'right', 'space'])
    # For the score, we use a 0 - 4 scale, and start at 2
    min_score = 0
    max_score = 4
    var.score = 2 # Use var to make this an experimental variable
    question = 'How awesome is OpenSesame?'
    while True:
        # Example: A score of two would be "XX___"
        # Clear the canvas and show this score string
        score_str = var.score*'X' + (max_score-var.score) * '_' 
        cnv.text('%s<br /><br />%s' % (question, score_str))
        # Collect a response, and break the loop (i.e. accept the response)
        # When a space is pressed. Decrease the score for 'left', and increase
        # the score for 'right'.
        response, timestamp = kb.get_key()
        if response == 'space':
        if response == 'left':
            var.score = max(min_score, var.score-1)
        elif response == 'right':
            var.score = min(max_score, var.score+1)

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

  • edited 2:54AM

    Hey Sebastien,

    Thanks a bunch!! Yes, I modified it a bit to suit the experiment, but on the whole its just perfect. Thanks a bunch!
    4 stars for you and Open Sesame.


Sign In or Register to comment.