Measure duration of key press
Hi! I'm making an experiment about time estimation, where the participant will hold down a key for three seconds (according to their own estimation). I'm having problem measuring the duration of the key press, though.
Here is one version I've tried, but when the experiment gets to the point of the inline script, the experiment stops and it says that it ended successfully. I'm new to OpenSesame and Python, so unfortunately I don't understand what goes wrong.
The prepare phase:

The run phase:

Comments
Hi Charlotte,
The reason nothing happened, is that you only broke out of the
forloop, but not out of thewhileloop. YOu would need another break statement outside the for loop that is only executed once you broke out of the for loop. Alternatively, you can also get rid of the for loop entirely (assuming that your participants are not pressing multiple keys simultaneously). Below is an example of the code for when you remove the for loop. I also added the presentation of a the current key press duration for illustration purposes.Does this make sense?
Eduard
@eduard is correct, of course. (You also mix up the name of the event, calling it
eventfirst andevlater.)But, just as a general remark, you can also use the
for ... elsepattern to deal with these kinds of nested loops, like so:See:
Check out SigmundAI.eu for our OpenSesame AI assistant!
Thank you so much, Eduard, it all works as it should now!
And thank you Sebastian, I didn't even think about doing it that way, it's good to know that's a possibility!
/Charlotte