Class KeyboardHandlerBase

Nested Relationships

Nested Types

Inheritance Relationships

Derived Types

Class Documentation

class KeyboardHandlerBase

Subclassed by KeyboardHandlerUnixImpl, KeyboardHandlerWindowsImpl

Public Types

enum class KeyModifiers : uint32_t

Enum for possible keys press combinations which keyboard handler capable to handle.

Enum for key modifiers such as CTRL, ALT and SHIFT pressed along side with base key.

Enum represented as a bitmask and could contain multiple values. Multiple values can be settled up with overloaded | logical OR operator and extracted with && operator.

Values:

enumerator NONE
enumerator SHIFT
enumerator ALT
enumerator CTRL
enum class KeyCode : uint32_t

Values:

enumerator UNKNOWN
enumerator EXCLAMATION_MARK
enumerator QUOTATION_MARK
enumerator HASHTAG_SIGN
enumerator DOLLAR_SIGN
enumerator PERCENT_SIGN
enumerator AMPERSAND
enumerator APOSTROPHE
enumerator OPENING_PARENTHESIS
enumerator CLOSING_PARENTHESIS
enumerator STAR
enumerator PLUS
enumerator COMMA
enumerator MINUS
enumerator DOT
enumerator RIGHT_SLASH
enumerator NUMBER_0
enumerator NUMBER_1
enumerator NUMBER_2
enumerator NUMBER_3
enumerator NUMBER_4
enumerator NUMBER_5
enumerator NUMBER_6
enumerator NUMBER_7
enumerator NUMBER_8
enumerator NUMBER_9
enumerator COLON
enumerator SEMICOLON
enumerator LEFT_ANGLE_BRACKET
enumerator EQUAL_SIGN
enumerator RIGHT_ANGLE_BRACKET
enumerator QUESTION_MARK
enumerator AT
enumerator LEFT_SQUARE_BRACKET
enumerator BACK_SLASH
enumerator RIGHT_SQUARE_BRACKET
enumerator CARET
enumerator UNDERSCORE_SIGN
enumerator GRAVE_ACCENT_SIGN
enumerator A
enumerator B
enumerator C
enumerator D
enumerator E
enumerator F
enumerator G
enumerator H
enumerator I
enumerator J
enumerator K
enumerator L
enumerator M
enumerator N
enumerator O
enumerator P
enumerator Q
enumerator R
enumerator S
enumerator T
enumerator U
enumerator V
enumerator W
enumerator X
enumerator Y
enumerator Z
enumerator LEFT_CURLY_BRACKET
enumerator VERTICAL_BAR
enumerator RIGHT_CURLY_BRACKET
enumerator TILDA
enumerator CURSOR_UP
enumerator CURSOR_DOWN
enumerator CURSOR_LEFT
enumerator CURSOR_RIGHT
enumerator ESCAPE
enumerator SPACE
enumerator ENTER
enumerator BACK_SPACE
enumerator DELETE_KEY
enumerator END
enumerator PG_DOWN
enumerator PG_UP
enumerator HOME
enumerator INSERT
enumerator F1
enumerator F2
enumerator F3
enumerator F4
enumerator F5
enumerator F6
enumerator F7
enumerator F8
enumerator F9
enumerator F10
enumerator F11
enumerator F12
enumerator END_OF_KEY_CODE_ENUM
using callback_t = std::function<void(KeyCode, KeyModifiers)>

Type for callback functions.

using callback_handle_t = uint64_t

Public Functions

KEYBOARD_HANDLER_PUBLIC callback_handle_t add_key_press_callback (const callback_t &callback, KeyboardHandlerBase::KeyCode key_code, KeyboardHandlerBase::KeyModifiers key_modifiers=KeyboardHandlerBase::KeyModifiers::NONE)

Adding callable object as a handler for specified key press combination.

Parameters
  • callback – Callable which will be called when key_code will be recognized.

  • key_code – Value from enum which corresponds to some predefined key press combination.

  • key_modifiers – Value from enum which corresponds to the key modifiers pressed along side with key.

Returns

Return Newly created callback handle if callback was successfully added to the keyboard handler, returns invalid_handle if callback is nullptr or keyboard handler wasn’t successfully initialized.

KEYBOARD_HANDLER_PUBLIC void delete_key_press_callback (const callback_handle_t &handle) noexcept

Delete callback from keyboard handler callback’s list.

Parameters

handle – Callback’s handle returned from add_key_press_callback

Public Static Attributes

static constexpr KEYBOARD_HANDLER_PUBLIC callback_handle_t invalid_handle   = 0

Callback handle returning from add_key_press_callback and using as an argument for the delete_key_press_callback.

Protected Attributes

bool is_init_succeed_ = false
std::mutex callbacks_mutex_
std::unordered_multimap<KeyAndModifiers, callback_data, key_and_modifiers_hash_fn> callbacks_
struct callback_data

Public Members

callback_handle_t handle
callback_t callback
struct key_and_modifiers_hash_fn

Specialized hash function for unordered_map with KeyAndModifiers.

Public Functions

inline std::size_t operator()(const KeyAndModifiers &key_and_mod) const
struct KeyAndModifiers

Public Functions

inline bool operator==(const KeyAndModifiers &rhs) const
inline bool operator!=(const KeyAndModifiers &rhs) const

Public Members

KeyCode key_code
KeyModifiers key_modifiers