Howdy, Stranger!

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

Supported by

using cursor_roi

Hi all and merry Christmas,

Does anyone have a simple script showing how to use cursor_roi? What I want is quite simple. I have a sketchpad (empty_array in the screenshot) with two squares on it. Then I add an inline to collect a mouse response. I could play with the x,y coordinates of the mouse response to figure out which square was clicked on but I think that the cursor_roi does this automatically, no? But, how do I do it? Plus, I don't see how the variable can return names of objects on the sketchpad when the objects are not named (both my squares are inserted as the same jpg). Any ideas?


  • Hi,

    I am not an expert on the mousetrap plugin, but I think if you don't have named objects on a sketchpad, you can't use the cursor_roi. @Pascal can you give us some insight here?


  • Hi Eduard and thanks for the response. I didn't realize that coursor_roi uses the mousetrap plugin. I'm not using that plugin at all, just some simple code to use the mouse. Also, how can you name anything on a sketchpad?? If I draw a square on a sketchpad, does it have a name? I only see a line of code that draws a square!

  • edited January 2


    you can name elements on the sketchpad by selecting the corresponding element and then entering a value in the name field that is displayed in the row above the sketchpad preview (the default value is auto, i.e., unspecified I think).

    Once you've done that, the name argument will be displayed in the OpenSesame script of the element, e.g.:

    draw rect color=white fill=0 h=160 name=myrectangle1 penwidth=1 show_if=always w=320 x=-448 y=-256 z_index=0

    If you want to do mouse-tracking via the mousetrap plugin, I would recommend that you draw the elements separately using two rect elements, name them (as described above) and then use a mousetrap_response item to implement the mouse-tracking and react to the clicks on the rectangles.

    The mousetrap-os item is documented here:

    A preprint of a book chapter that includes a tutorial can be found here:

    However, the cursor_roi procedure should also work once you've named the elements.



  • Dear Pascal,

    Thank you very much for this! It makes sense now. I'll try out the mousetrap plugin as well and read the preprint.



  • Hi Pascal,

    First off, I should say that the chapter is fantastic. Thanks for sharing. Now, I have installed mousetrap and tried to use the mousetrap_response item after a sketchpad but I get an unexpected error when I run the experiment (AttributeError: 'Xpyriment' object has no attribute 'w'). I tried different backends but I get the same thing. I attach a screeenshot with the debug window.

    Also, is there a way to have more than 4 buttons as options? For this experiment I'm not so much interested in tracking. I just want to know which box was clicked (out of hopefully 9-10 boxes).

  • Hi Marios,

    I think the problem is that the mousetrap plugin only supports rect elements. If you inserted the buttons as pictures, you would have to draw an additional rect element around them and label this element to get the click in the respective area of interest (AOI). More than four buttons are possible if you use the Python implementation of the plugin (see mousetrap_response_python.osexp example at But if you are not interested in the mouse movements and want to use the pictures, then you could also probably try using the cursor_roi implementation of OpenSesame - I think this implementation should also support pictures as AOIs.



  • Pascal, me again. I have redrawn the buttons and it now works. Don't know what was wrong before but now it's fine. The only thing now is whether there is a workaround in terms of the numbers of buttons I can have. Any ideas?



  • Thanks for your response Pascal. We must have been writing at the same time and saw it after I posted mine. I will try the Python implementation as I know I will be using the Mousetrap plugin for other experiments that will require mouse tracking. About the cursor_roi implementation....I have no idea how to use it. That was in fact my initial post. I just can't find any example of that anywhere. You can see my inline script attached on my first post which shows how I use the mouse. But, no idea how to use cursor_roi and it seems to me that there's a straightforward way!


  • Hi Marios,

    Te cursor_roi functionality is unrelated to Mousetrap (although Mousetrap uses it). Here's a simple video tutorial that should show you the basics of how it works!



  • Thanks Sebastiaan. That was even more simple than I thought!


  • Good to hear!

Sign In or Register to comment.