This PDF was auto-generated on 2015-07-02 22:29:29 +0200. A more recent version of this page may be available at http://osdoc.cogsci.nl/python/mouse/. 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) 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 – 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 visible – True to show the cursor, False to hide. (If you are using the legacy backend, 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 visible – True to show the cursor, False to hide. (If you are using the legacy backend, 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: visible – True to show the cursor, False to hide. (If you are using the legacy backend, 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 Copyright 2010-2015 Sebastiaan Mathôt // Download as .tar.gz // Revision #219810 on Thu Jul 2 20:29:15 2015
© Copyright 2024