expyriment.io.Mouse¶
-
class
expyriment.io.
Mouse
(show_cursor=True, track_button_events=None, track_motion_events=None, quit_click_rect_size=None)[source]¶ A class implementing a mouse input.
Calling expyriment.control.intialize(exp) will automatically create a mouse instance and will reference it in exp.mouse for easy access.
Attributes
Methods
-
__init__
(show_cursor=True, track_button_events=None, track_motion_events=None, quit_click_rect_size=None)[source]¶ Initialize a mouse input.
Parameters: show_cursor : bool, optional
shows mouse cursor (default = True)
track_button_events : bool, optional
track button events via Pygame queue (default = True)
track_motion_events : bool, optional
track motion events via Pygame queue (default = False)
Notes
(a) It is strongly suggest to avoid tracking of motions events, (track_motion_events=True), because it quickly causes an overflow in the Pygame event queue and you might consequently loose important events.
(b) See process_quit_event for the forced quitting of experiments via mouse events.
Return False or button id if a specific button is currently pressed.
Parameters: button_number : int
the button number (0,1,2) to be checked
Returns: is_pressed: boolean :
-
check_wheel
()[source]¶ Check the mouse wheel.
Returns: direction : str
“up” or “down” if mouse wheel has been recently rotated upwards or downwards otherwise it returns None.
Get the last button down event. All earlier button down events will be removed from the queue.
Parameters: process_quit_event : boolean, optional
- if False, the current location will not be processed for mouse
quitting events in the case that a button down event has been found (default = True).
Returns: btn_id : int
button number (0,1,2) or 3 for wheel up or 4 for wheel down, if quit screen mouse action has been performed, the method returns -1
Get the last button up event. All earlier button up events will be removed from the queue.
Returns: btn_id : int
button number (0,1,2) if quit screen mouse action has been performed, the method returns -1
-
hide_cursor
(track_button_events=False, track_motion_events=False)[source]¶ Hide the cursor.
Parameters: track_button_events : bool, optional
tracking button events (default = True)
track_motion_events : bool, optional
tracking motion events (default = False)
-
is_cursor_visible
¶ returns if cursor is visible
-
logging
¶ Getter for logging.
-
position
¶ Getter of mouse position.
Getter for pressed buttons.
-
static
process_quit_event
(click_position=None)[source]¶ Check if mouse exit action has been performed
If Mouse.quit_rect_location is defined (i.e. 0, 1, 2 or 3), clicking quickly three times (i.e., within 1 second) in one of the corners of the screen forces the experiment to quit.
The function is called automatically by all mouse get event and wait methods (similar to Keyboard.process_control_keys). If no mouse functions are called by your program, this function can be polled to ensure quitting experiment by mouse.
Mouse quit events are especially useful for experiments on devices without hardware keyboard, such as tablet PCs or smartphones.
Parameters: click_position : tuple of int (x,y), optional
clicked location to be processed. If not defined, the Pygame event queue will be checked for mouse down events and the current position is taken
Returns: out : bool, optional
True if exit action has been performed False otherwise
Notes
To switch on or off the detection of mouse quit events, please use the static class property `quit_rect_location’ (see below).
The detection of mouse quit events is activated by default under Android.
- Mouse.quit_rect_location = int, optional
Location of the quit click action field or None.
0 = upper left corner, 1 = upper right corner (0) (1) 2 = lower right corner, 3 = lower left corner (3) (2) otherwise the detection of mouse quit events is deactivated.
Default value under Android is 1, otherwise None
- Mouse.quit_click_rect_size : tuple (int, int)
- size of the field (rect) that detects the quit action by triple clicking in one corner of the screen. (default = (30, 30))
Changing the static class properties affects always all mouse instances.
-
set_cursor
(size, hotspot, xormasks, andmasks)[source]¶ Set the cursor.
Parameters: size : (int, int)
size of the cursor
hotspot : (int, int)
position of the hotspot (0,0 is top left)
xormask : list
sequence of bytes with cursor xor data masks
andmask : list
sequence of bytes with cursor bitmask data
-
set_logging
(onoff)¶ Set logging of this object on or off
Parameters: onoff : bool
set logging on (True) or off (False)
Notes
See also design.experiment.set_log_level fur further information about event logging.
-
show_cursor
(track_button_events=True, track_motion_events=False)[source]¶ Show the cursor.
Parameters: track_button_events : bool, optional
tracking button events (default = True)
track_motion_events : bool, optional
tracking motion events (default = False)
Getter for track_button_events.
-
track_motion_events
¶ Getter for track_motion_events.
Switch on/off the buffering of motion events in the Pygame event queue.
Notes
It is strongly suggest to avoid tracking of motions events, (track_motion_events=True), because it quickly causes an overflow in the Pygame event queue and you might consequently loose important events.
-
wait_event
(wait_button=True, wait_motion=True, buttons=None, duration=None, wait_for_buttonup=False)[source]¶ Wait for a mouse event (i.e., motion, button press or wheel event)
Parameters: wait_button : bool, optional
set ‘False’ to ignore for a button presses (default=True)
wait_motion : bool, optional
set ‘False’ to ignore for a mouse motions (default=True)
buttons : int or list, optional
a specific button or list of buttons to wait for
duration : int, optional
the maximal time to wait in ms
wait_for_buttonup : bool, optional
if True it waits for button-up default=False)
Returns: event_id : int
id of the event that quited waiting
move : bool
True if a motion occured
pos : (int, int)
mouse position (tuple)
rt : int
reaction time
See also
design.experiment.register_wait_callback_function
Notes
button id coding
- None for no mouse button event or
- 0,1,2 for left. middle and right button or
- 3 for wheel up or
- 4 for wheel down (wheel works only for keydown events).
-
wait_motion
(duration=None)[source]¶ Wait for a mouse motion.
Parameters: duration : int, optional
maximal time to wait in ms
Returns: pos : (int, int)
mouse position (tuple)
rt : int
reaction time
-
wait_press
(buttons=None, duration=None, wait_for_buttonup=False)[source]¶ Wait for a mouse button press or mouse wheel event.
Parameters: buttons : int or list, optional
a specific button or list of buttons to wait for
duration : int, optional
maximal time to wait in ms
wait_for_buttonup : bool, optional
if True it waits for button-up
Returns: event_id : int
id of the event that quited waiting
pos : (int, int)
mouse position (tuple)
rt : int
reaction time
Notes
button id coding
- None for no mouse button event or
- 0,1,2 for left. middle and right button or
- 3 for wheel up or
- 4 for wheel down (wheel works only for keydown events).
-