1
0
mirror of https://github.com/TomHarte/CLK.git synced 2025-01-15 20:31:36 +00:00

Merge pull request #1160 from TomHarte/ADBKeyboard

Avoid flurry of startup events, repeats.
This commit is contained in:
Thomas Harte 2023-08-22 09:42:03 -04:00 committed by GitHub
commit 598a889c6d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 2 deletions

View File

@ -72,8 +72,13 @@ void Keyboard::did_receive_data(const Command &, const std::vector<uint8_t> &dat
bool Keyboard::set_key_pressed(Key key, bool is_pressed) { bool Keyboard::set_key_pressed(Key key, bool is_pressed) {
// ADB keyboard events: low 7 bits are a key code; bit 7 is either 0 for pressed or 1 for released.
std::lock_guard lock_guard(keys_mutex_); std::lock_guard lock_guard(keys_mutex_);
if(pressed_keys_[size_t(key)] == is_pressed) {
return true;
}
// ADB keyboard events: low 7 bits are a key code;
// bit 7 is either 0 for pressed or 1 for released.
pending_events_.push_back(uint8_t(key) | (is_pressed ? 0x00 : 0x80)); pending_events_.push_back(uint8_t(key) | (is_pressed ? 0x00 : 0x80));
pressed_keys_[size_t(key)] = is_pressed; pressed_keys_[size_t(key)] = is_pressed;

View File

@ -106,7 +106,7 @@ class Keyboard: public ReactiveDevice {
void did_receive_data(const Command &, const std::vector<uint8_t> &) override; void did_receive_data(const Command &, const std::vector<uint8_t> &) override;
std::mutex keys_mutex_; std::mutex keys_mutex_;
std::array<bool, 128> pressed_keys_; std::array<bool, 128> pressed_keys_{};
std::vector<uint8_t> pending_events_; std::vector<uint8_t> pending_events_;
uint16_t modifiers_ = 0xffff; uint16_t modifiers_ = 0xffff;
}; };