1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-12-23 20:29:42 +00:00

Avoid flurry of startup events, repeats.

This commit is contained in:
Thomas Harte 2023-08-22 09:28:57 -04:00
parent 525e5ce8b0
commit e5d3140cd1
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) {
// 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_);
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));
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;
std::mutex keys_mutex_;
std::array<bool, 128> pressed_keys_;
std::array<bool, 128> pressed_keys_{};
std::vector<uint8_t> pending_events_;
uint16_t modifiers_ = 0xffff;
};