diff options
author | Zach Eveland <zeveland@blacklabel-development.com> | 2012-03-28 19:46:32 -0400 |
---|---|---|
committer | Zach Eveland <zeveland@blacklabel-development.com> | 2012-03-28 19:46:32 -0400 |
commit | 1534b2b730af952d836ecaf79563fa54f689720b (patch) | |
tree | 280ca8935217f6f9b376093a47df9becb949d137 | |
parent | 83feb140138d1c7900619ac2a733885e192987a8 (diff) |
fixed logic error in Keyboard.release() - now removes every occurrence of a key if it's present more than once
-rw-r--r-- | cores/arduino/HID.cpp | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/cores/arduino/HID.cpp b/cores/arduino/HID.cpp index cdf49bd..ac63608 100644 --- a/cores/arduino/HID.cpp +++ b/cores/arduino/HID.cpp @@ -435,7 +435,7 @@ size_t Keyboard_::press(uint8_t k) setWriteError(); return 0; } - if (k & 0x80) { + if (k & 0x80) { // it's a capital letter or other character reached with shift _keyReport.modifiers |= 0x02; // the left shift modifier k &= 0x7F; } @@ -478,22 +478,20 @@ size_t Keyboard_::release(uint8_t k) if (!k) { return 0; } - if (k & 0x80) { + if (k & 0x80) { // it's a capital letter or other character reached with shift _keyReport.modifiers &= ~(0x02); // the left shift modifier k &= 0x7F; } } // Test the key report to see if k is present. Clear it if it exists. + // Check all positions in case the key is present more than once (which it shouldn't be) for (i=0; i<6; i++) { - if (_keyReport.keys[i] == k) { + if (0 != k && _keyReport.keys[i] == k) { _keyReport.keys[i] = 0x00; - break; } } - if (i == 6) { - return 0; - } + sendReport(&_keyReport); return 1; } @@ -514,7 +512,7 @@ size_t Keyboard_::write(uint8_t c) { uint8_t p = press(c); // Keydown uint8_t r = release(c); // Keyup - return (p&r); + return (p); // just return the result of press() since release() almost always returns 1 } #endif |