InputHandler: only call listeners when the key's state has changed
This commit is contained in:
parent
657f3ea479
commit
ccf859fe80
1 changed files with 8 additions and 8 deletions
|
@ -51,18 +51,18 @@ public:
|
|||
}
|
||||
|
||||
void keyPressed(uint16_t key, uint64_t time) {
|
||||
pressedKeys.insert(key);
|
||||
|
||||
if (pressedKeys.insert(key).second) {
|
||||
for (auto &listener : listeners)
|
||||
listener(key, true, time);
|
||||
}
|
||||
}
|
||||
|
||||
void keyReleased(uint16_t key, uint64_t time) {
|
||||
pressedKeys.erase(key);
|
||||
|
||||
if (pressedKeys.erase(key)) {
|
||||
for (auto &listener : listeners)
|
||||
listener(key, false, time);
|
||||
}
|
||||
}
|
||||
|
||||
bool isKeyPressed(uint16_t key) {
|
||||
return pressedKeys.count(key);
|
||||
|
|
Reference in a new issue