Class KeyMap

Class Documentation

class KeyMap

The KeyMap class maps key+modifier combinations to actions.

Actions are the fundamental unit of interaction with the user. Rather than respond to keycodes or characters, code that uses a KeyMap abstraction can instead respond to actions, and actions can be mapped to different key/character combinations without requiring (potentially) widespread change in lower-level code and systems.

Public Functions

virtual ~KeyMap()
virtual void Add(UTF8Char keyChar, UTF8String action, uint8_t modifier) = 0

Add a new, or overwrite an existing, mapping from key/modifier to action.

The mapping is maintained as a key/value table, and the key type in this table is a combination of keycode/character, and optional modifiers (see Modifier). Therefore the same character can be used in different contexts (such as 'A' and 'CTRL+A') to map to different actions.

Parameters
  • keyChar -- Base UTF-8 character to map (example 'A', '+', etc.)

  • action -- User-provided UTF-8 string to which keyChar maps. There are no reserved actions from the perspective of KeyMap.

  • modifier -- Modifier key (and member of Modifier enum); example, SHIFT, CTRL, etc.

virtual UTF8String Lookup(UTF8Char keyChar, uint8_t modifier) const = 0

Obtain UTF-8 action string that corresponds to the combination of keyChar and modifier.

Parameters
  • keyChar -- Base UTF-8 character to look up.

  • modifier -- Member of Modifier enum corresponding to one or more modifier keys to use in performing the lookup.

Returns

If the combination of keyChar and modifier map to a previously-defined action, the UTF-8 string containing the action name/text. Otherwise, nullptr.

virtual bool IsEmpty() const = 0

Detect whether the keymap is empty.

Returns

True if no entries exist in the keymap, false if entries exist.