Previous topic

psychopy.data - functions for storing/saving/analysing data

Next topic

psychopy.filters - helper functions for creating filters

Quick links

psychopy.event - for getting keypress and mouse clicks

To handle from keyboard, mouse and joystick (joysticks require pygame to be installed). See demo_mouse.py and i{demo_joystick.py} for examples

class psychopy.event.Mouse(visible=True, newPos=None, win=None)

Easy way to track what your mouse is doing. It needn’t be a class, but since Joystick works better as a class this may as well be one too for consistency

Create your visual.Window before creating a Mouse.

Parameters:
visible : True or False

makes the mouse invisbile if necessary

newPos : None or [x,y]

gives the mouse a particular starting position (pygame Window only)

win : None or Window

the window to which this mouse is attached (the first found if None provided)

getPos()
Returns the current postion of the mouse, in the same units as the Window (0,0) is at centre
getPressed()
Returns a 3-item list indicating whether or not buttons 1,2,3 are currently pressed
getRel()
Returns the new position of the mouse relative to the last call to getRel or getPos, in the same units as the Window.
getVisible()
Gets the visibility of the mouse (1 or 0)
getWheelRel()
Returns the travel of the mouse scroll wheel since last call. Returns a numpy.array(x,y) but for most wheels y is the only value that will change (except mac mighty mice?)
setPos(newPos=(0, 0))

Sets the current postiion of the mouse (pygame only), in the same units as the Window (0,0) is at centre

Parameters:
newPos : (x,y) or [x,y]

the new position on the screen

setVisible(visible)

Sets the visibility of the mouse to 1 or 0

NB when the mouse is not visible its absolute position is held at (0,0) to prevent it from going off the screen and getting lost! You can still use getRel() in that case.

psychopy.event.clearEvents(eventType=None)

Clears all events currently in the event buffer. Optional argument, eventType, specifies only certain types to be cleared

Parameters:
eventType : None, ‘mouse’, ‘joystick’, ‘keyboard’

If this is not None then only events of the given type are cleared

psychopy.event.getKeys(keyList=None, timeStamped=False)

Returns a list of keys that were pressed.

Parameters:
keyList : None or []

Allows the user to specify a set of keys to check for. Only keypresses from this set of keys will be removed from the keyboard buffer. If the keyList is None all keys will be checked and the key buffer will be cleared completely. NB, pygame doesn’t return timestamps (they are always 0)

timeStamped : False or True or Clock

If True will return a list of tuples instead of a list of keynames. Each tuple has (keyname, time). If a core.Clock is given then the time will be relative to the Clock‘s last reset

Author:
  • 2003 written by Jon Peirce
  • 2009 keyList functionality added by Gary Strangman
  • 2009 timeStamped code provided by Dave Britton
psychopy.event.waitKeys(maxWait=None, keyList=None)

Halts everything (including drawing) while awaiting input from keyboard. Then returns list of keys pressed. Implicitly clears keyboard, so any preceding keypresses will be lost.

Optional arguments specify maximum wait period and which keys to wait for.

Returns None if times out.