8 for (
const Event& event : eventQueue) {
11 case Event::Type::Press: {
12 Key key = std::get<Key>(event.data);
13 state.
keysDown[
static_cast<size_t>(key)] =
true;
16 case Event::Type::Release: {
17 Key key = std::get<Key>(event.data);
18 state.
keysDown[
static_cast<size_t>(key)] =
false;
21 case Event::Type::AddChar: {
22 state.
chars += std::get<std::string>(event.data);
25 case Event::Type::Reset: {
35 events = std::move(eventQueue);
40 eventQueue.push_back({Event::Type::Press, timestamp, {key}});
44 eventQueue.push_back({Event::Type::Release, timestamp, {key}});
48 eventQueue.push_back({Event::Type::AddChar, timestamp, {std::move(ch)}});
52 eventQueue.push_back({Event::Type::Reset, timestamp, {}});
56 for (
const Event& e : events)
57 if (e.type == Event::Type::Press && std::get<Key>(e.data) == key)
62 for (
const Event& e : events)
63 if (e.type == Event::Type::Release && std::get<Key>(e.data) == key)
void submitKeyDown(Key key, double timestamp)
Queue key down event for being processed in the next update.
void submitReset(double timestamp)
Queue reset event for being processed in the next update.
void submitKeyUp(Key key, double timestamp)
Queue key up event for being processed in the next update.
void submitChar(std::string ch, double timestamp)
Queue char event for being processed in the next update.
bool wasKeyPressed(Key key) const
Return true if the key was pressed in the last frame, false otherwise.
void update()
Reset the state and events and update them from the eventQueue.
bool wasKeyReleased(Key key) const
Return true if the key was released in the last frame, false otherwise.
bool keysDown[static_cast< size_t >(Key::Count)]
State of tracked keys.
std::string chars
List of characters generated by the keyboard this frame.