You are viewing unmaintained documentation for an older version of OpenSesame. Click here to view the current documentation. Your version of OpenSesame: Language:

OpenSesame 3.0.0 will bring amazing new features! Curious? Take it for a test spin, and help us iron out the kinks.

Mouse functions

class mouse

The mouse class is used to collect mouse input.

Important note:

When using a mouse all coordinates are specified relative to the top-left of the display, and not, as in sketchpads, relative to the display center. For example, the following script will determine the deviation of a mouse click relative to the display center.

Example:

from openexp.mouse import mouse
from openexp.canvas import canvas
my_mouse = mouse(exp)
my_canvas = canvas(exp)
while True:
        button, position, timestamp = my_mouse.get_click(timeout=20)
        if button != None:
                break
        pos, time = my_mouse.get_pos()
        my_canvas.clear()
        my_canvas.fixdot(pos[0], pos[1])
        my_canvas.show()

Function list:

function mouse.__init__(experiment, visible=False, timeout=None, buttonlist=None)

Intializes the mouse object.

Example:

from openexp.mouse import mouse
my_mouse = mouse(exp)

Arguments:

  • experiment – The experiment object.
    • Type: experiment

Keywords:

  • buttonlist – A list of buttons that are accepted or None to accept all buttons.
    • Type: list, NoneType
    • Default: None
  • timeout – A numeric value specifying a timeout in milliseconds or None for no (i.e. infinite) timeout.
    • Type: int, float, NoneType
    • Default: None
  • visibleTrue to show the cursor, False to hide. (If you are using the legacy back-end, you may find that the mouse cursor is not visible. For a workaround, see http://osdoc.cogsci.nl/back-ends/legacy/.)
    • Type: bool
    • Default: False

function mouse.flush()

Clears all pending input, not limited to the mouse.

Example:

from openexp.mouse import mouse
my_mouse = mouse(exp)
my_mouse.flush()
button, position, timestamp = my_mouse.get_click()

Returns:

True if a button had been clicked (i.e., if there was something to flush) and False otherwise.

  • Type: bool

function mouse.get_click(visible=None, timeout=None, buttonlist=None)

Waits for mouse input.

Example:

from openexp.mouse import mouse
my_mouse = mouse(exp)
button, position, timestamp = my_mouse.get_click()
if button == None:
        print('A timeout occurred!')

Keywords:

  • buttonlist – A list of buttons that are accepted or None to accept all buttons.
    • Type: list, NoneType
    • Default: None
  • timeout – A numeric value specifying a timeout in milliseconds or None for no (i.e. infinite) timeout.
    • Type: int, float, NoneType
    • Default: None
  • visibleTrue to show the cursor, False to hide. (If you are using the legacy back-end, you may find that the mouse cursor is not visible. For a workaround, see http://osdoc.cogsci.nl/back-ends/legacy/.)
    • Type: bool
    • Default: None

Returns:

A (button, position, timestamp) tuple. The button and position are None if a timeout occurs. Position is an (x, y) tuple in screen coordinates.

  • Type: tuple

function mouse.get_pos()

Returns the current position of the cursor.

Example:

from openexp.mouse import mouse
my_mouse = mouse(exp)
position, timestamp = my_mouse.get_pos()
x, y = position
print('The cursor was at (%d, %d)' % (x, y))

Returns:

A (position, timestamp) tuple.

  • Type: tuple

function mouse.get_pressed()

Returns the current state of the mouse buttons. A True value means the button is currently being pressed.

Example:

from openexp.mouse import mouse
my_mouse = mouse(exp)
buttons = my_mouse.get_pressed()
b1, b2, b3 = buttons
print('Currently pressed mouse buttons: (%d,%d,%d)' % (b1,b2,b3))

Returns:

A (button1, button2, button3) tuple of boolean values.

  • Type: tuple.

function mouse.set_buttonlist(buttonlist=None)

Sets a list of accepted buttons.

Example:

from openexp.mouse import mouse
my_mouse = mouse(exp)
my_mouse.set_buttonlist( [1,2] )

Keywords:

  • buttonlist – A list of buttons that are accepted or None to accept all buttons.
    • Type: list, NoneType
    • Default: None

function mouse.set_pos(pos=(0, 0))

Sets the position of the mouse cursor.

Example:

from openexp.mouse import mouse
my_mouse = mouse(exp)
my_mouse.set_pos(pos=(0,0))

Keywords:

  • pos – An (x,y) tuple for the new mouse coordinates.
    • Type: tuple
    • Default: (0, 0)

function mouse.set_timeout(timeout=None)

Sets a timeout.

Example:

from openexp.mouse import mouse
my_mouse = mouse(exp)
my_mouse.set_timeout(2000)

Keywords:

  • timeout – A numeric value specifying a timeout in milliseconds or None for no (i.e. infinite) timeout.
    • Type: int, float, NoneType
    • Default: None

function mouse.set_visible(visible=True)

Sets the visibility of the cursor.

Example:

from openexp.mouse import mouse
my_mouse = mouse(exp)
my_mouse.set_visible()

Keywords:

  • visibleTrue to show the cursor, False to hide. (If you are using the legacy back-end, you may find that the mouse cursor is not visible. For a workaround, see http://osdoc.cogsci.nl/back-ends/legacy/.)
    • Type: bool
    • Default: True

function mouse.synonyms(button)

Gives a list of synonyms for a mouse button. For example, 1 and ‘left_click’ are synonyms.

Arguments:

  • button – A button value.
    • Type: int, str, unicode

Returns:

A list of synonyms.

  • Type: list