KeyboardManager: a class to manage the polling of a switch-matrix keyboard
Diff: SingleKeyPressMonitor.cpp
- Revision:
- 2:eb4cc53ff33d
- Child:
- 3:1310c57aca77
diff -r a74ffceb67e5 -r eb4cc53ff33d SingleKeyPressMonitor.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SingleKeyPressMonitor.cpp Sun Jan 23 23:15:36 2011 +0000 @@ -0,0 +1,30 @@ +#include "kbd_mgr/SingleKeyPressMonitor.h" + +namespace kbd_mgr { + +void SingleKeyPressMonitor::operator()(const KeyboardState &newState) +{ + int key; + if (newState.getKeyPressType(key) == KeyboardState::SingleKeyPress && this->lastReportedState.empty()) + { + if (this->handler) { + (*this->handler)(key, true); + } + + this->lastReportedState = newState; + this->lastReportedKey = key; + } + else if (!this->lastReportedState.empty() && + (newState & this->lastReportedState).empty()) + { + if (this->handler) { + (*this->handler)(this->lastReportedKey, false); + } + + this->lastReportedState.clear(); + this->lastReportedKey = KeyPressEventHandler::NoKey; + } + +} + +} // kbd_mgr \ No newline at end of file