These are the devices that receive key commands from some external source and route them to your applications.
At the input system core, there’s
InputListener. It receives key events from drivers you use and routes them to currently active application.
Available input drivers:
i variable you have supplied by
load_app() in your applications is an
InputListener instance. It’s operating on key names, such as “KEY_ENTER” or “KEY_UP”. You can assign callback once a keypress with a matching keyname is received, which is as simple as
You can also set a dictionary of
"keyname":callback_function mappings, this would be called a
A class which listens for input device events and calls corresponding callbacks if set
Init function for creating KeyListener object. Checks all the arguments and sets keymap if supplied.
Exits driver (if necessary) if something wrong happened or pyLCI exits. Also, stops the listener
Raises exceptions upon setting of a special callback on a reserved/taken keyname
Removes all the callbacks set
Blocking event loop which just calls callbacks in the keymap once corresponding keys are received in the
Start event_loop in a thread. Nonblocking.
This is the method that receives keypresses from drivers and puts them into
Removes a single callback of the listener
Removes a callback for streaming key events, if previously set by any app/UI element.
Sets all the callbacks supplied, not removing previously set but overwriting those with same keycodes
Sets a single callback of the listener
Sets all the callbacks supplied, removing the previously set keymap completely
Sets a single maskable callback of the listener. Raises CallbackException if the callback is one of the reserved keys or already is in maskable/nonmaskable keymap.
A maskable callback is global (never cleared) and will be called upon a keypress unless a callback for the same keyname is already set in keymap.
Sets a single nonmaskable callback of the listener. Raises CallbackException if the callback is one of the reserved keys or already is in maskable/nonmaskable keymap.
A nonmaskable callback is global (never cleared) and will be called upon a keypress even if a callback for the same keyname is already set in
keymap(callback from the
keymapwon’t be called).
Sets a callback for streaming key events. The callback will be called with key_name as first argument but should support arbitrary number of positional arguments if compatibility with future versions is desired.
This sets a flag for
event_loopto stop. It also calls a
stopmethod of the input driver
In v1.0 architecture, there’s a single
InputListener instance shared among all applications, so when you set some callbacks for your application and then exit it or execute your application’s menu element, there’s a very good chance your callbacks won’t be there anymore once you return.
You won’t need to think about it unless you’re setting
InputListener yourself - mostly it’s taken care of by UI objects, which set the keymaps themselves themselves (for example,
Menu UI element sets the callbacks each time a menu is activated and each time a menu element callback execution is finished (because a
Menu can’t be sure whatever got called by the callback didn’t set some of callbacks some other way, say, the element’s callback was activating a nested menu.)
If you do set callbacks/keymap yourself (very useful for making your own UI elements, or for applications needing custom keybindings), it’s important to remember that you need to stop
InputListener before and start it again afterwards, since the changes do not take place until that’s done. For example, this is how you would set your own callback:
i.stop_listen() i.clear_keymap() #Useful because there might be callbacks left from whatever your function was called by #... Set your callbacks i.set_callback("KEY_ENTER", my_function) i.listen()
Glue logic functions
Not for user interaction, are called by
main.py, which is pyLCI launcher.
This function is called by main.py to read the input configuration, pick the corresponding drivers and initialize InputListener.
It also sets
inputmodule with driver and listener respectively, as well as registers
listener.stop()function to be called when script exits since it’s in a blocking non-daemon thread.