InputHandler: only call listeners when the key's state has changed

This commit is contained in:
Matthias Schiffer 2014-09-24 14:27:10 +02:00
parent 657f3ea479
commit ccf859fe80

View file

@ -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);