KeyboardManager: a class to manage the polling of a switch-matrix keyboard
KeyboardState Class Reference
A class to hold the state of a keyboard. More...
#include <KeyboardState.h>
Public Member Functions | |
KeyboardState () | |
Constructor for a 0x0 keyboard state. | |
KeyboardState (std::size_t numRows, std::size_t numKeysPerRow) | |
Constructor for a NxM keyboard state. | |
KeyboardState | operator^ (const KeyboardState &other) const |
Executes a XOR between two states. | |
KeyboardState | operator& (const KeyboardState &mask) const |
Executes an AND between two states. | |
bool | empty () const |
Checks if a keyboard state is full of 0. | |
KeyPressType | getKeyPressType (int *key=NULL) const |
Determines the kind of key press present in the state. |
Detailed Description
A class to hold the state of a keyboard.
A keyboard is handled as a set of key rows. Each row can have as many keys as there are bits in integers. The class maintains an array of integers to handle the number of rows. If possible, multiple rows are combined in a single integer to reduce memory footprint.
Definition at line 15 of file KeyboardState.h.
Constructor & Destructor Documentation
KeyboardState | ( | ) |
Constructor for a 0x0 keyboard state.
Definition at line 8 of file KeyboardState.cpp.
KeyboardState | ( | std::size_t | numRows, |
std::size_t | numKeysPerRow | ||
) |
Constructor for a NxM keyboard state.
- Parameters:
-
numRows Number of key rows (unlimited) numKeysPerRow Number of keys per row (limited to the number of bits in an integer).
Definition at line 12 of file KeyboardState.cpp.
Member Function Documentation
bool empty | ( | ) | const |
Checks if a keyboard state is full of 0.
Definition at line 96 of file KeyboardState.cpp.
KeyboardState::KeyPressType getKeyPressType | ( | int * | key = NULL ) |
const |
Determines the kind of key press present in the state.
The keyboard state can represent an idle keyboard, a single key pressed or a key combination. This method determines which type of state this is. If a single key is represented, the key index can be retrieved.
- Parameters:
-
key An integer where the single key pressed should be stored.
Definition at line 123 of file KeyboardState.cpp.
KeyboardState operator& | ( | const KeyboardState & | mask ) | const |
Executes an AND between two states.
Definition at line 58 of file KeyboardState.cpp.
KeyboardState operator^ | ( | const KeyboardState & | other ) | const |
Executes a XOR between two states.
- Returns:
- a state that represents the keys that changed of state.
Generated on Thu Jul 14 2022 19:25:04 by 1.7.2