Class KeyboardHandlerWindowsImpl

Nested Relationships

Nested Types

Inheritance Relationships

Base Type

Class Documentation

class KeyboardHandlerWindowsImpl : public KeyboardHandlerBase

Windows specific implementation of keyboard handler class.

Note

Design and implementation limitations: Can’t detect CTRL + ALT combinations. Can’t detect CTRL + 0..9 number keys. Can’t detect ALT + F1..12 keys. Instead of CTRL + SHIFT + key will be detected only CTRL + key. Some keys might be incorrectly detected with multiple key modifiers pressed at the same time.

Public Types

using isattyFunction = std::function<int(int)>
using kbhitFunction = std::function<int(void)>
using getchFunction = std::function<int(void)>

Public Functions

KEYBOARD_HANDLER_PUBLIC KeyboardHandlerWindowsImpl()

Default constructor.

virtual KEYBOARD_HANDLER_PUBLIC ~KeyboardHandlerWindowsImpl()

Destructor.

KEYBOARD_HANDLER_PUBLIC std::tuple< KeyboardHandlerBase::KeyCode, KeyboardHandlerBase::KeyModifiers > win_key_code_to_enums (WinKeyCode win_key_code) const

Translates WinKeyCode to the key code and key modifiers enum values.

Parameters:

win_key_code – Key codes returning by Windows OS in response to the pressing keyboard keys.

Returns:

tuple key code and code modifiers mask.

KEYBOARD_HANDLER_PUBLIC WinKeyCode enum_key_code_to_win_code (KeyboardHandlerBase::KeyCode key_code) const

Translates internally defined KeyCode enum value to the corresponding WinKeyCode registered in inner look up table.

Parameters:

key_code – Internally defined KeyCode enum value.

Returns:

Returns WinKeyCode value corresponding to the input KeyCode enum value in the inner lookup table. If corresponding WinKeyCode value not found in inner LUT will return WinKeyCode with NOT_A_KEY values.

Protected Functions

KEYBOARD_HANDLER_PUBLIC KeyboardHandlerWindowsImpl(const isattyFunction &isatty_fn, const kbhitFunction &kbhit_fn, const getchFunction &getch_fn)

Constructor with references to the system functions. Required for unit tests.

Parameters:
  • isatty_fn – Reference to the system _isatty(int) function

  • kbhit_fn – Reference to the system _kbhit(void) function

  • getch_fn – Reference to the system _getch(void) function

Protected Static Attributes

static const KeyMap DEFAULT_STATIC_KEY_MAP[]

Default statically defined lookup table for corresponding KeyCode enum value and expecting sequence of key codes returning by _getch() in response to the pressing keyboard keys.

static const size_t STATIC_KEY_MAP_LENGTH

Length of DEFAULT_STATIC_KEY_MAP measured in number of elements.

struct KeyMap

Data type for mapping KeyCode enum value to the expecting sequence of key codes returning by _getch() in response to the pressing keyboard keys.

Public Members

KeyboardHandlerBase::KeyCode inner_code
WinKeyCode win_key_code
struct win_key_code_hash_fn

Specialized hash function for unordered_map with WinKeyCode keys.

Public Functions

inline std::size_t operator()(const WinKeyCode &key_code) const
struct WinKeyCode

Data type for representing key codes returning by _getch() function in response to the pressing keyboard keys.

Windows OS could return up to two integer values in response to the pressing keyboard key combination. If Windows returning only one value it will be placed in first field and second field will be initialized with NOT_A_KEY value.

Public Functions

inline bool operator==(const WinKeyCode &rhs) const

Equality operator for comparison of two WinKeyCodes.

Parameters:

rhs – Value for comparison from right hand side.

Returns:

Returns true if two key codes are equal, otherwise false.

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

Not equal operator for comparison of two WinKeyCodes.

Parameters:

rhs – Value for comparison from right hand side.

Returns:

Returns true if two key codes are not equal, otherwise false.

Public Members

int first
int second

Public Static Attributes

static constexpr int NOT_A_KEY = -1

Predefined value which is corresponding to the invalid or empty value for WinKeyCode elements.