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:
parent
525e5ce8b0
commit
e5d3140cd1
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user