scamp_extensions.interaction.key_plane.KeyPlane
- class scamp_extensions.interaction.key_plane.KeyPlane(callback: Callable, normalize_coordinates: bool = False)[source]
Bases:
object
Abstraction used to transform keyboard input into a two-dimensional control space. Each key pressed corresponds to a vertical and horizontal position, which is passed to the callback function, along with (optionally) whether it was an up or down keystroke and what modifiers were present.
- Parameters:
callback – a function of the form “callback(coordinates, up_or_down, modifiers)”. Can also have the signature “callback(coordinates, up_or_down)” or “callback(coordinates)”, in which case it is simply not passed that information.
normalize_coordinates – if True, the keys coordinates go from 0-1 horizontally and vertically. if False, they go from 0-3 (inclusive) vertically and 0-9, 10 or 11 horizontally (depending on row)
- Variables:
modifiers_down – a list of modifier keys currently pressed
Methods
start
([suppress, blocking, session])Starts up the KeyPlane listening to keyboard input.
Attributes
tuple of all names of modifier keys
Callback function as described in the constructor, which responds to keyboard presses.
- all_modifiers = ('ctrl', 'alt', 'shift', 'cmd', 'caps_lock', 'tab', 'enter', 'backspace', 'up', 'left', 'down', 'up')
tuple of all names of modifier keys
- property callback: Callable
Callback function as described in the constructor, which responds to keyboard presses.
- start(suppress: bool = False, blocking: bool = False, session: Optional[bool] = None) None [source]
Starts up the KeyPlane listening to keyboard input.
- Parameters:
suppress – if True, suppresses all other keyboard events so that nothing gets triggered unintentionally. (Make sure you have a way of stopping the script with the mouse!)
blocking – if True causes this call to block (by calling
wait_forever()
on the underlyingscamp.session.Session
).session – a
scamp.session.Session
on which to run the keyboard listener. If None, looks to see if there’s a session running on the current thread.