Skip to content

Commit

Permalink
Merge pull request felis#52 from weizenspreu/master
Browse files Browse the repository at this point in the history
Event for changed control keys
  • Loading branch information
Oleg Mazurov committed May 16, 2013
2 parents 216fce8 + a669933 commit 2a43fde
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
38 changes: 38 additions & 0 deletions examples/HID/USBHIDBootKbd/USBHIDBootKbd.ino
Expand Up @@ -20,6 +20,8 @@ class KbdRptParser : public KeyboardReportParser
void PrintKey(uint8_t mod, uint8_t key);

protected:
virtual void OnControlKeysChanged(uint8_t before, uint8_t after);

virtual void OnKeyDown (uint8_t mod, uint8_t key);
virtual void OnKeyUp (uint8_t mod, uint8_t key);
virtual void OnKeyPressed(uint8_t key);
Expand Down Expand Up @@ -54,6 +56,42 @@ void KbdRptParser::OnKeyDown(uint8_t mod, uint8_t key)
OnKeyPressed(c);
}

void KbdRptParser::OnControlKeysChanged(uint8_t before, uint8_t after) {

MODIFIERKEYS beforeMod;
*((uint8_t*)&beforeMod) = before;

MODIFIERKEYS afterMod;
*((uint8_t*)&afterMod) = after;

if (beforeMod.bmLeftCtrl != afterMod.bmLeftCtrl) {
Serial.println("LeftCtrl changed");
}
if (beforeMod.bmLeftShift != afterMod.bmLeftShift) {
Serial.println("LeftShift changed");
}
if (beforeMod.bmLeftAlt != afterMod.bmLeftAlt) {
Serial.println("LeftAlt changed");
}
if (beforeMod.bmLeftGUI != afterMod.bmLeftGUI) {
Serial.println("LeftGUI changed");
}

if (beforeMod.bmRightCtrl != afterMod.bmRightCtrl) {
Serial.println("RightCtrl changed");
}
if (beforeMod.bmRightShift != afterMod.bmRightShift) {
Serial.println("RightShift changed");
}
if (beforeMod.bmRightAlt != afterMod.bmRightAlt) {
Serial.println("RightAlt changed");
}
if (beforeMod.bmRightGUI != afterMod.bmRightGUI) {
Serial.println("RightGUI changed");
}

}

void KbdRptParser::OnKeyUp(uint8_t mod, uint8_t key)
{
Serial.print("UP ");
Expand Down
5 changes: 5 additions & 0 deletions hidboot.cpp
Expand Up @@ -52,6 +52,11 @@ void KeyboardReportParser::Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t

//KBDINFO *pki = (KBDINFO*)buf;

// provide event for changed control key state
if (prevState.bInfo[0x00] != buf[0x00]) {
OnControlKeysChanged(prevState.bInfo[0x00], buf[0x00]);
}

for (uint8_t i = 2; i < 8; i++) {
bool down = false;
bool up = false;
Expand Down
5 changes: 4 additions & 1 deletion hidboot.h
Expand Up @@ -161,7 +161,10 @@ class KeyboardReportParser : public HIDReportParser {
protected:
virtual uint8_t HandleLockingKeys(HID* hid, uint8_t key);

virtual void OnKeyDown(uint8_t mod, uint8_t key) {
virtual void OnControlKeysChanged(uint8_t before, uint8_t after) {
};

virtual void OnKeyDown(uint8_t mod, uint8_t key) {
};

virtual void OnKeyUp(uint8_t mod, uint8_t key) {
Expand Down

0 comments on commit 2a43fde

Please sign in to comment.