Howdy, Stranger!

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

Supported by

[solved] How to get Keyboard module to accept <Enter>

edited September 2011 in OpenSesame
Hello,
In OpenSesame, I am writing an experiment using inline script to have participants type responses to audio stimuli. I am using the OpenSesame Keyboard module to collect their keypresses, and collect multiple keypresses for every audio stimulus. Therefore, the keypress collecting is done in a sentinel loop (While var != "": ). What I would like to be able to do is have participants exit the loop by pressing the key. How can I get OS to recognize the keypress in this way and thus exit the sentinel loop?

Comments

  • edited 1:54AM

    Hi Adam,

    There are quite a lot of ways to do this, but the trick in general is to use a very short timeout value, and exit the loop as soon as a timeout has not occurred. So something like this should get you started:

    from openexp.keyboard import keyboard
    my_keyboard = keyboard(self.experiment, timeout=20)
    start_time = self.time()
    while True:
    # Perform some task here
    key, end_time = my_keyboard.get_key()
    if key != None:
    break
    self.experiment.set("response", my_keyboard.to_chr(key))
    self.experiment.set("response_time", end_time-start_time)

    Hope this helps!

    More keyboard functions: http://osdoc.cogsci.nl/python-inline-code/keyboard-functions

    Kindest regards,
    Sebastiaan

Sign In or Register to comment.