PyGaze - documentation - libinput
The input library is used to create objects that communicate with external hardware. Apart from the standard Mouse and Keyboard, a Joystick class is provided as well. This class may be used for joysticks, gamepads and the like: basically anything that has buttons, balls, hats and a joystick* should be compatible.
* something with a hat, buttons, balls, and a joystick? if that makes you chuckle, wait 'til you see this!
contents
MouseMouse.set_mousebuttonlist
Mouse.set_timeout
Mouse.set_visible
Mouse.set_pos
Mouse.get_pos
Mouse.get_clicked
Mouse.get_pressed
Keyboard
Keyboard.set_keylist
Keyboard.set_timeout
Keyboard.get_key
Joystick
Joystick.set_joybuttonlist
Joystick.set_timeout
Joystick.get_joybutton
Joystick.get_joyaxes
Joystick.get_joyballs
Joystick.get_joyhats
Joystick.get_joyinput
Mouse
An object for collecting mouse input and manipulating the cursor position and visibility
arguments | |
---|---|
None | |
keyword arguments | |
disptype | display type, either 'psychopy' or 'pygame' (default = DISPTYPE) |
mousebuttonlist | list of mouse buttons that are allowed (e.g. [1,3] for left and right button) or None to allow all buttons (default = MOUSEBUTTONLIST) |
timeout | time in milliseconds after which None is returned on a call to get_clicked method when no click is registered (default = MOUSETIMEOUT) |
visible | Boolean indicating if mouse should be visible or not (default = False) |
Set a list of accepted mouse buttons
arguments | |
---|---|
None | |
keyword arguments | |
mousebuttonlist | list of mouse buttons that are allowed (e.g. [1,3] for left and right button) or None to allow all buttons (default = None) |
returns | |
None | sets mbuttonlist property |
Set a timeout (in milliseconds)
arguments | |
---|---|
None | |
keyword arguments | |
timeout | time in milliseconds after which None is returned on a call to get_clicked method when no click is registered (default = None) |
returns | |
None | sets timeout property |
Sets the visibility of the cursor
arguments | |
---|---|
None | |
keyword arguments | |
visible | Boolean indicating if mouse should be visible or not (default = False) |
returns | |
None | sets visible property |
Set the mouse position
arguments | |
---|---|
None | |
keyword arguments | |
pos | an (x,y) position tuple (default = (0,0)) |
returns | |
None | directly adjusts the mouse position |
Returns mouse position
arguments | |
---|---|
None | |
keyword arguments | |
None | |
returns | |
mpos | an (x,y) position tuple |
Waits for a mouse click
arguments | |
---|---|
None | |
keyword arguments | |
mousebuttonlist | list of mouse buttons that are allowed (e.g. [1,3] for left and right button); None to allow all buttons or 'default' to use the mbuttonlist property (default = 'default') |
timeout | time in milliseconds after which None is returned when no click is registered; None for no timeout or 'default' to use the timeout property (default = 'default') |
returns | |
mousebutton, clickpos, clicktime | mousebutton is an integer, indicating which button has been pressed or None when no button has been pressed; clickpos is an (x,y) position tuple or None when no click was registered; clicktime is the time (measured from expbegintime) a buttonpress or a timeout occured |
Returns the current state of the mouse buttons
arguments | |
---|---|
None | |
keyword arguments | |
None | |
returns | |
statelist | a list of Booleans indicating which mousebutton is currently down (e.g. [1,0,0] when only button 1 is being pressed on a three-button-mouse) |
Keyboard
An object for collecting keyboard input
arguments | |
---|---|
None | |
keyword arguments | |
disptype | display type, either 'psychopy' or 'pygame' (default = DISPTYPE) |
keylist | list of keys that are allowed, e.g. ['1','a','enter'] for the 1, A and Enter keys (default = KEYLIST) |
timeout | time in milliseconds after which None is returned on a call to the get_key method when no keypress is registered (default = KEYTIMEOUT) |
Set a list of accepted keys
arguments | |
---|---|
None | |
keyword arguments | |
keylist | list of keys that are allowed (e.g. ['1','a','enter']) or None to allow all keys (default = None) |
returns | |
None | sets klist property |
Set a timeout (in milliseconds)
arguments | |
---|---|
None | |
keyword arguments | |
timeout | time in milliseconds after which None is returned on a call to get_key method when no keypress is registered (default = None) |
returns | |
None | sets timeout property |
Wait for keyboard input
arguments | |
---|---|
None | |
keyword arguments | |
keylist | list of keys that are allowed (e.g. ['1','a','enter']), None to allow all keys or 'default' to use klist property (default = 'default') |
timeout | time in milliseconds after which None is returned when no keypress is registered (default = None); None for no timeout or 'default' to use the timeout property (default = 'default') |
returns | |
key, presstime | key is a string, indicating which button has been pressed or None when no key has been pressed presstime is the time (measured from expbegintime) a keypress or a timeout occured |
Joystick
An object for collecting joystick input
arguments | |
---|---|
None | |
keyword arguments | |
joybuttonlist | list of joystick buttons that are allowed (e.g. [0,2,4], keep in mind that they start at 0!) or None to allow all buttons (default = JOYBUTTONLIST) |
timeout | time in milliseconds after which None is returned on a call to a get_* method when no input is registered (default = JOYTIMEOUT) |
Set a list of accepted joystick buttons
arguments | |
---|---|
None | |
keyword arguments | |
joybuttonlist | list of joystick buttons that are allowed (e.g. [0,2,4]) or None to allow all buttons (default = None) |
returns | |
None | sets the jbuttonlist property |
Set a timeout (in milliseconds)
arguments | |
---|---|
None | |
keyword arguments | |
timeout | time in milliseconds after which None is returned on a call to get_clicked method when no click is registered (default = None) |
returns | |
None | sets timeout property |
Waits for joystick buttonpress
arguments | |
---|---|
None | |
keyword arguments | |
joybuttonlist | list of buttons that are allowed (e.g. [0,2,4]), None to allow all buttons or 'default' to use jbuttonlist property (default = 'default') |
timeout | time in milliseconds after which None is returned when no buttonpress is registered; None for no timeout or 'default' to use the timeout property (default = 'default') |
returns | |
button, presstime | button is an integer, indicating which button has been pressed or None when no button has been pressed presstime is the time (in milliseconds, measured from expbegintime) a buttonpress or a timeout occured |
Waits for joystick axis movement
arguments | |
---|---|
None | |
keyword arguments | |
timeout | time in milliseconds after which None is returned when no axis movement is registered; None for no timeout or 'default' to use the timeout property (default = 'default') |
returns | |
axespos, time | axespos is a [x,y,z] position list for the positions of the joystick axes (usually [x,y,z] for the main stick); x, y and z are floats time is the time (in milliseconds, measured from expbegintime) an axismovement or a timeout occured |
Waits for joystick trackball movement
arguments | |
---|---|
None | |
keyword arguments | |
timeout | time in milliseconds after which None is returned when no ball movement is registered; None for no timeout or 'default' to use the timeout property (default = 'default') |
returns | |
ballpos, time | ballpos is a [ball1,ball2,...,ballN] position list for the positions of the joystick balls; each ball position is a (x,y) tuple time is the time (in milliseconds, measured from expbegintime) a ballmovement or a timeout occured |
Waits for joystick hat movement
arguments | |
---|---|
None | |
keyword arguments | |
timeout | time in milliseconds after which None is returned when no hat movement is registered; None for no timeout or 'default' to use the timeout property (default = 'default') |
returns | |
hatpos, time | hatpos is a [hat1,hat2,...,hatN] position list for the positions of the joystick hats; each hat position is a (x,y) tuple time is the time (in milliseconds, measured from expbegintime) a hatmovement or a timeout occured |
Waits for any kind of joystick input
arguments | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
None | |||||||||||
keyword arguments | |||||||||||
joybuttonlist | list of buttons that are allowed (e.g. [0,2,4]), None to allow all buttons or 'default' to use jbuttonlist property (default = 'default') | ||||||||||
timeout | time in milliseconds after which None is returned when no joystick input is registered; None for no timeout or 'default' to use the timeout property (default = 'default') | ||||||||||
returns | |||||||||||
event, input, time | event is a string or None on a timeout, indicating what kind of input was given:
|
full source
You can find the full source code for libinput.py on GitHub.