Permalink
Browse files

Added KeyboardReportParser::OnControlKeysChanged(before, after) to be…

… able to react on control key presses and enhanced the HID keyboard example.
  • Loading branch information...
Kenneth Newwood
Kenneth Newwood committed May 16, 2013
1 parent 1a362c5 commit a669933c4434b781c16f88dd1f9da9c92ac19dd3
Showing with 47 additions and 1 deletion.
  1. +38 −0 examples/HID/USBHIDBootKbd/USBHIDBootKbd.ino
  2. +5 −0 hidboot.cpp
  3. +4 −1 hidboot.h
@@ -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);
@@ -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 ");
@@ -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;
@@ -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) {

0 comments on commit a669933

Please sign in to comment.