mirror of
https://github.com/arduino/Arduino.git
synced 2025-03-14 11:29:26 +01:00
fixed logic error in Keyboard.release() - now removes every occurrence of a key if it's present more than once
This commit is contained in:
parent
b86ec2723a
commit
97d9ce93ca
@ -435,7 +435,7 @@ size_t Keyboard_::press(uint8_t k)
|
|||||||
setWriteError();
|
setWriteError();
|
||||||
return 0;
|
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
|
_keyReport.modifiers |= 0x02; // the left shift modifier
|
||||||
k &= 0x7F;
|
k &= 0x7F;
|
||||||
}
|
}
|
||||||
@ -478,22 +478,20 @@ size_t Keyboard_::release(uint8_t k)
|
|||||||
if (!k) {
|
if (!k) {
|
||||||
return 0;
|
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
|
_keyReport.modifiers &= ~(0x02); // the left shift modifier
|
||||||
k &= 0x7F;
|
k &= 0x7F;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test the key report to see if k is present. Clear it if it exists.
|
// 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++) {
|
for (i=0; i<6; i++) {
|
||||||
if (_keyReport.keys[i] == k) {
|
if (0 != k && _keyReport.keys[i] == k) {
|
||||||
_keyReport.keys[i] = 0x00;
|
_keyReport.keys[i] = 0x00;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (i == 6) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
sendReport(&_keyReport);
|
sendReport(&_keyReport);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -514,7 +512,7 @@ size_t Keyboard_::write(uint8_t c)
|
|||||||
{
|
{
|
||||||
uint8_t p = press(c); // Keydown
|
uint8_t p = press(c); // Keydown
|
||||||
uint8_t r = release(c); // Keyup
|
uint8_t r = release(c); // Keyup
|
||||||
return (p&r);
|
return (p); // just return the result of press() since release() almost always returns 1
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user