KeyboardManager: a class to manage the polling of a switch-matrix keyboard

Dependents:   KeyboardTest

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers SingleKeyPressMonitor.cpp Source File

SingleKeyPressMonitor.cpp

00001 #include "kbd_mgr/SingleKeyPressMonitor.h"
00002 
00003 namespace kbd_mgr {
00004 
00005 void SingleKeyPressMonitor::handleState(const KeyboardState &newState)
00006 {
00007     int key;
00008     if (newState.getKeyPressType(key) == KeyboardState::SingleKeyPress && this->lastReportedState.empty()) 
00009     {
00010         KeyEvent keyDown(key, KeyEvent::KeyDown);
00011         invokeHandler(keyDown);
00012         
00013         this->lastReportedState = newState;
00014         this->lastReportedKey = key;
00015     }
00016     else if (!this->lastReportedState.empty() &&
00017              (newState & this->lastReportedState).empty())
00018     {
00019         KeyEvent keyUp(this->lastReportedKey, KeyEvent::KeyUp);
00020         invokeHandler(keyUp);
00021                 
00022         this->lastReportedState.clear();
00023         this->lastReportedKey = KeyEvent::NoKey;
00024     }
00025 
00026 }
00027 
00028 } // kbd_mgr