Skip to content

Integration into Other Modules

shbatm edited this page Jun 22, 2017 · 15 revisions

The MMM-KeyBindings Module must be integrated into other modules in order for it to be useful. See information below on how to receive key press events in your module.

Detailed Reference

Refer to handleKeys.js for source code and documentation for receiving and handling key press events in your module.

Receiving Key Presses

When a key is pressed, this module will send a module notification on with the following properties (if the key is not a special key, handled by this module):

notification: "KEYPRESS"
payload: {  CurrentMode: "DEFAULT",  // "Mode" or "Focus" to respond to
            KeyCode: "Enter",        // The plain text key name pressed
            KeyState: "KEY_PRESSED", // What happened
            Sender: "SERVER",        // Source of the input.
            Duration: 0.1234         // Duration of keypress (evdev only)
            SpecialKeys: [],         // Internal Module Processing (evdev only)
}
Parameter Description
CurrentMode The current "Mode" or "Focus". "DEFAULT" is the default mode. Your module should check the mode and respond appropriately. See Changing Modes below.
KeyCode The plain text name of the key that was pressed. Remote control keys are normalized to the Standard Keyboard Enumeration where possible.
KeyState The type of key press. Options are:
KEY_PRESSED - a normal key press.
KEY_LONGPRESSED - a long key press.
KEY_UP or keyup - key released*
KEY_DOWN or keydown - key pressed* down
KEY_HOLD - a key being held*
* Raw Mode Only
Sender The sender either "SERVER" if sent by evdev or a keyboard connected to the server running the mirror; otherwise "LOCAL".

Changing Focus

A module can request focus or a "Mode" change one of two ways:

  1. Send a notification to request it:

    this.sendNotification("KEYPRESS_MODE_CHANGED","MODE NAME");
  2. Adding an External Interrupt Special Key (extInterruptX) in this module's config:
    This has the advantage that it will short-circuit all other modules and the mode will be changed before sending out the keypress.

All subsequent key presses will be sent with the new mode. Make sure to release the focus when done by sending a mode change of "DEFAULT" back.

External Mode Interrupt Keys

Three of the special keys can be assigned to change the mode in combination with the extInterruptModes parameter. For example, if you wanted the "KEY_MENU" key to always open a menu in another module and give that module focus, you could set:

    specialKeys: { extInterrupt1: { KeyName: "KEY_MENU", KeyState: "KEY_PRESSED" } }
    extInterruptModes: ["MY_MODULES_MENU"],
Clone this wiki locally