T his PDF was auto- generated on 2014- 11- 04... .

T his PDF was auto- generated on 2014- 11- 04 11:02:17 +0100. A more recent version of this page may
be available at http://osdoc.cogsci.nl/python/mouse/.
Mouse functions
class mouse
T he 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)
function mouse.flush()
function mouse.get_click(visible=None, timeout=None, buttonlist=None)
function mouse.get_pos()
function mouse.get_pressed()
function mouse.set_buttonlist(buttonlist=None)
function mouse.set_pos(pos=(0, 0))
function mouse.set_timeout(timeout=None)
function mouse.set_visible(visible=True)
function mouse.synonyms(button)
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 – T he experiment object.
T ype: experiment
Keywords:
visible – True to show the cursor, False to hide.
Default: False
T ype: bool
buttonlist – A list of buttons that are accepted or None to accept all
buttons.
Default: None
T ype: list, NoneT ype
timeout – A numeric value specifying a timeout in milliseconds or None for no
(i.e. infinite) timeout.
Default: None
T ype: int, float, NoneT ype
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.
T ype: 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:
visible – True to show the cursor, False to hide.
Default: None
T ype: bool
buttonlist – A list of buttons that are accepted or None to accept all
buttons.
Default: None
T ype: list, NoneT ype
timeout – A numeric value specifying a timeout in milliseconds or None for no
(i.e. infinite) timeout.
Default: None
T ype: int, float, NoneT ype
Returns:
A (button, position, timestamp) tuple. T he button and position are None if a
timeout occurs. Position is an (x, y) tuple in screen coordinates.
T ype: 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.
T ype: 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.
T ype: 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.
Default: None
T ype: list, NoneT ype
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.
Default: (0, 0)
T ype: tuple
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.
Default: None
T ype: int, float, NoneT ype
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:
visible – True to show the cursor, False to hide.
Default: T rue
T ype: bool
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.
T ype: int, str, unicode
Returns:
A list of synonyms.
T ype: list
Copyright 2010- 2014 S eba stia a n Ma thôt // Downloa d a s .ta r.gz // Revision #dddf21 on T ue Nov 4 10:02:02 2014