From ccf859fe805afe8db3aa694df5d26da7778dfc68 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Wed, 24 Sep 2014 14:27:10 +0200 Subject: InputHandler: only call listeners when the key's state has changed --- src/control/InputHandler.hpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/control/InputHandler.hpp b/src/control/InputHandler.hpp index 1a34982..7eb98a9 100644 --- a/src/control/InputHandler.hpp +++ b/src/control/InputHandler.hpp @@ -51,17 +51,17 @@ public: } void keyPressed(uint16_t key, uint64_t time) { - pressedKeys.insert(key); - - for (auto &listener : listeners) - listener(key, true, time); + if (pressedKeys.insert(key).second) { + for (auto &listener : listeners) + listener(key, true, time); + } } void keyReleased(uint16_t key, uint64_t time) { - pressedKeys.erase(key); - - for (auto &listener : listeners) - listener(key, false, time); + if (pressedKeys.erase(key)) { + for (auto &listener : listeners) + listener(key, false, time); + } } bool isKeyPressed(uint16_t key) { -- cgit v1.2.3