mirror of
https://github.com/felis/USB_Host_Shield_2.0.git
synced 2024-03-22 11:31:26 +01:00
Added KeyboardReportParser::OnControlKeysChanged(before, after) to be able to react on control key presses and enhanced the HID keyboard example.
This commit is contained in:
parent
1a362c5310
commit
a669933c44
3 changed files with 47 additions and 1 deletions
|
@ -20,6 +20,8 @@ class KbdRptParser : public KeyboardReportParser
|
||||||
void PrintKey(uint8_t mod, uint8_t key);
|
void PrintKey(uint8_t mod, uint8_t key);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
virtual void OnControlKeysChanged(uint8_t before, uint8_t after);
|
||||||
|
|
||||||
virtual void OnKeyDown (uint8_t mod, uint8_t key);
|
virtual void OnKeyDown (uint8_t mod, uint8_t key);
|
||||||
virtual void OnKeyUp (uint8_t mod, uint8_t key);
|
virtual void OnKeyUp (uint8_t mod, uint8_t key);
|
||||||
virtual void OnKeyPressed(uint8_t key);
|
virtual void OnKeyPressed(uint8_t key);
|
||||||
|
@ -54,6 +56,42 @@ void KbdRptParser::OnKeyDown(uint8_t mod, uint8_t key)
|
||||||
OnKeyPressed(c);
|
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)
|
void KbdRptParser::OnKeyUp(uint8_t mod, uint8_t key)
|
||||||
{
|
{
|
||||||
Serial.print("UP ");
|
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;
|
//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++) {
|
for (uint8_t i = 2; i < 8; i++) {
|
||||||
bool down = false;
|
bool down = false;
|
||||||
bool up = false;
|
bool up = false;
|
||||||
|
|
|
@ -161,7 +161,10 @@ public:
|
||||||
protected:
|
protected:
|
||||||
virtual uint8_t HandleLockingKeys(HID* hid, uint8_t key);
|
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) {
|
virtual void OnKeyUp(uint8_t mod, uint8_t key) {
|
||||||
|
|
Loading…
Reference in a new issue