[solved] set duration as either mouseclick or keypress
Is there a way to set the duration of a sketchpad as either keypress or mouseclick whichever comes first?
Thanks in advance
Ezer
Is there a way to set the duration of a sketchpad as either keypress or mouseclick whichever comes first?
Thanks in advance
Ezer
Comments
Hi Ezerkar,
Thank you for your interest in OpenSesame!
No, there's no way to do that through the GUI, but you can set the duration to '0' and add a simple inline_script after the sketchpad:
# Import and create mouse and keyboard objects from openexp.keyboard import keyboard from openexp.mouse import mouse my_keyboard = keyboard(self.experiment, timeout=5) my_mouse = mouse(self.experiment, timeout=5) # Wait until a key has been pressed or button has been clicked start_time = self.time() while True: resp, time = my_keyboard.get_key() if resp != None: resp = my_keyboard.to_chr(resp) break resp, pos, time = my_mouse.get_click() if resp != None: break # Store the response self.experiment.set("response", resp) self.experiment.set("response_time", time-start_time)For more information, see
http://osdoc.cogsci.nl/python-inline-code/keyboard-functions
http://osdoc.cogsci.nl/python-inline-code/mouse-functions
Hope this helps!
Regards,
Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
Thanks, that helps a lot.
Ezer
Very helpful answer. Thanks too.
One more detail:
If I only want certain keypresses, lets say F, G,H, and J, plus any mouse clicks, where do i insert this?
like that?
resp, time = my_keyboard.get_key(f;g;h;j)
Hi,
The general procedure is explain here and here
If you want to use both, mouse and keyboard responses, you should sample responses in a
loop, e.g. like so:I hope this helps.
Eduard