From e5d3140cd17e507b99cb41999fcfd9002c1ddef8 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Tue, 22 Aug 2023 09:28:57 -0400 Subject: [PATCH] Avoid flurry of startup events, repeats. --- Machines/Apple/ADB/Keyboard.cpp | 7 ++++++- Machines/Apple/ADB/Keyboard.hpp | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Machines/Apple/ADB/Keyboard.cpp b/Machines/Apple/ADB/Keyboard.cpp index fd89a06df..5eaf2619c 100644 --- a/Machines/Apple/ADB/Keyboard.cpp +++ b/Machines/Apple/ADB/Keyboard.cpp @@ -72,8 +72,13 @@ void Keyboard::did_receive_data(const Command &, const std::vector &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; diff --git a/Machines/Apple/ADB/Keyboard.hpp b/Machines/Apple/ADB/Keyboard.hpp index 7438f6bc6..e205d7bdf 100644 --- a/Machines/Apple/ADB/Keyboard.hpp +++ b/Machines/Apple/ADB/Keyboard.hpp @@ -106,7 +106,7 @@ class Keyboard: public ReactiveDevice { void did_receive_data(const Command &, const std::vector &) override; std::mutex keys_mutex_; - std::array pressed_keys_; + std::array pressed_keys_{}; std::vector pending_events_; uint16_t modifiers_ = 0xffff; };