-
Notifications
You must be signed in to change notification settings - Fork 15
userinput
userinput provides a all of a devices physical inputs in one place.
At its core, the module is based on the device-specific _keys
module, which provides logic for reading the keypresses and converting them into readable strings. The UserInput
class subclasses the _keys.Keys
class, and inherits those device-specific features.
UserInput
can also provide other kinds of input, such as providing touch data from a device with a touchscreen. These extra features, of course, are based on the specific device being used.
The UserInput
class also handles key-repeating behaviour, and locking modifier keys.
This module was previously the
lib.smartkeyboard
module. It has been renamed and expanded for MicroHydra 2.x to support different devices and input methods.
userinput.UserInput(hold_ms=600, repeat_ms=80, use_sys_commands=True, allow_locking_keys=False, **kwargs)
Creat the object for accessing user inputs.
Args:
hold_ms
:
The amount of time, in milliseconds, a key must be held before it starts to repeat.
repeat_ms
:
While a key is being held and repeating, how long between repetitions.
use_sys_commands
:
Whether or not to enable keyboard shortcuts for built-in system commands
allow_locking_keys
:
Whether or not to allow modifier keys to 'lock' (stay activated when tapped). This draws an overlay on the screen using the display module.
**kwargs
:
Any other keyword args given are passed along to the_keys.Keys
class, allowing for device-specific options to be used.
UserInput.get_pressed_keys()
Return a list of strings, representing the names of keys that are currently being pressed.
UserInput.get_new_keys()
Return a list of strings, representing the names of keys that are newly pressed (are now pressed but were not pressed last time we checked).
This method also runs additional logic based on the settings provided in the constructor:
key repeating logic:
Keys will return when they are new, and periodically after they have been held down for the time specified byUserInput.hold_ms
locking keys logic:
Whenallow_locking_keys
isTrue
, if a modifier key is pressed without pressing another key, that key will be 'locked', and held until it is pressed again.
This also draws an overlay (displaying the locked keys) to the screen using a callback every timeDisplay.show()
is called.
UserInput.get_mod_keys()
Return a list of modifier keys that are being held, including keys that are locked if
allow_locking_keys
isTrue
.
These methods only exist when the device has a touchscreen
UserInput.get_current_points()
Return the current touch data in the form of a list of
TouchPoints
Touchpoints arenamedtuple
s with the following format:
namedtuple("TouchPoint", ["id", "x", "y", "size"])
UserInput.get_touch_events()
Similar to
get_new_keys
, this method does some pre-processing on touch data to make it easier to parse.Touch events are only returned once, when they are completed, and take the form of either a
Tap
or aSwipe
:
namedtuple("Tap", ['x', 'y', 'size', 'duration'])
namedtuple("Swipe", ['x0', 'y0', 'x1', 'y1', 'size', 'duration', 'distance', 'direction'])