[solved] Question on mouse response with inline script
Hi all!
In an old thread (http://www.cogsci.nl/forum/index.php?p=/discussion/143/open-how-do-i-collect-the-keyboard_response-after-a-stimulus-disappears/p1) I found this really nice piece of code, which enables measuring keyboard response time from the onset of a stimulus.
This is exactly what I need for my experiment and it works perfectly, but I would like to use a mouse response, instead of a keyboard response. I tried to change the code, but I was not able to do so ![]()
Precisely, I do not know how this command should be for the mouse response:
resp, time = my_keyboard.get_key(timeout=timeout)
and also this part of the code:
response = my_keyboard.to_chr(resp)
Sorry, if this is naive (I am not very experienced in programming and do not understand everything in the documentation), but I did not find the to_chr() function in either the keyboard or mouse response documentation, what does it even do?
Best regards,
Martin

Comments
Hi Martin,
The equivalent of
get_key()for mouse objects isget_click().In older versions of OpenSesame,
get_key()returned an ASCII key code, and you had to useto_chr()to convert this code to a character. Nowadays,get_key()returns a unicode representation of the key, soto_chr()is no longer needed. It's still there to avoid breaking old experiments, but it doesn't do anything.Hope this clears things up!
Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
Hi Sebastiaan,
thanks for your quick reply. I get that the get_click() function is the equivalent to the get_key() function. I fear I still do not understand how this line
should be for my mouse_response code. The response object should simply save which mouse button was pressed. I tried some commands, but none of them worked.
EDIT: I tried this command:
but it gave me this error: xpyriment instance has no call method
EDIT 2: This command:
gave me the error argument of type 'int' is not iterable
Thanks again in advance! Best regards,
Martin
Hi Martin
get_click()doesn't return a single value, but a so-called tuple, which is a set of variables. You have to 'unpack' this tuple into a response, a position, and a time variable. For example, like so:or like so
Tuples are part of the basic Python syntax. I would recommend walking through one of the entry-level Python tutorials, such A Byte of Python.
Cheers!
Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
Hi Sebastiaan,
thanks again for your reply! You are right, I really should redo some of the basic Python syntax, this will probably help me a lot. I just wanted to say that even without expert programming skills, I am now working on the third experiment in only the few weeks since I have found OpenSesame, thanks to the excellent software and your helpfulness in this forum
I just seem to have a hard time with mouse responses. I have not been able to save the button which was clicked into a variable in the logger. It does not work with inline script (that was why I was asking above) and also with simple mouse response items.
I just created a new experiment, in which I only created a sketchpad, a mouse response and a logger item. I enabled every variable that was accociated with the mouse response to be logged. None of these variables saved which button was clicked. The variable 'response' only gave the output undefined (it was None when I used an inline script). Is this a bug in my OpenSesame version? I am using Windows 7 and the latest stable OpenSesame version. I really feel stupid about the mouse response problems that I am having
Thanks again, Martin!
Hi Martin,
Could you perhaps upload your experimental script, for example to pastebin?
Cheers,
Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
Hi Sebastiaan,
you can find the test experiment here: http://pastebin.com/UgLVfYHX
I just tried using a different mouse, but the experiment never saves the click that has been made into the logger.
Greetings, Martin
Hi Martin,
For me, your experiment works fine. You should see the mouse response in the following columns:
responseandresponse_mouse_responsecursor_xcursor_yresponse_timeandresponse_time_mouse_responseThe
responseshould be 1, 2, or 3, for respectively the left, middle, and right button.If you don't see this, something is pretty wrong. What version of OpenSesame and what operating system are you using?
Cheers,
Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
Hi Sebastiaan,
I now see my problem: I used a variable
correct_responsein the experimental loop, in which I labled the possible correct answers as 'left_button' and 'right_button', don't ask me why, I am not sure. The thing is, this actually worked! I got correct responses (=1) in mycorrectvariable when I answered correctly and incorrect responses when I answered incorrectly. I now realized, however, that theresponse_mouse_responsevariable does not save 'left_button' or 'right_button' as output, but '1' and '3'.The problem is probably that I am building the experiments on the computer, on which they will be running and I do not have much software on it. So, most often I look into into the data output using a simple text editor, which is not convenient. I was only looking for the output 'right_ or left_button' and not for '1' or '3'.
Thank you and sorry for the trouble, my mistake. Btw now everything works for me
With best regards,
Martin