diff --git a/src/kaleidoscope/plugin/Qukeys.cpp b/src/kaleidoscope/plugin/Qukeys.cpp index e9a9637e..67643acc 100644 --- a/src/kaleidoscope/plugin/Qukeys.cpp +++ b/src/kaleidoscope/plugin/Qukeys.cpp @@ -118,6 +118,14 @@ EventHandlerResult Qukeys::beforeReportingState() { } } + // Next, if there hasn't been a keypress in a while, update the prior keypress + // timestamp to avoid integer overflow issues: + if (Runtime.hasTimeExpired(prior_keypress_timestamp_, + minimum_prior_interval_)) { + prior_keypress_timestamp_ = + Runtime.millisAtCycleStart() - (minimum_prior_interval_ + 1); + } + // If any events get flushed from the queue, stop there; we can only safely // send the one report per cycle. if (processQueue()) { @@ -134,14 +142,6 @@ EventHandlerResult Qukeys::beforeReportingState() { queue_head_.primary_key : queue_head_.alternate_key; flushEvent(event_key); } - - // Last, if there hasn't been a keypress in a while, update the prior keypress - // timestamp to avoid integer overflow issues: - if (Runtime.hasTimeExpired(prior_keypress_timestamp_, - minimum_prior_interval_)) { - prior_keypress_timestamp_ = - Runtime.millisAtCycleStart() - (minimum_prior_interval_ + 1); - } return EventHandlerResult::OK; } diff --git a/src/kaleidoscope/plugin/Qukeys.h b/src/kaleidoscope/plugin/Qukeys.h index e4b5d320..78ad0e52 100644 --- a/src/kaleidoscope/plugin/Qukeys.h +++ b/src/kaleidoscope/plugin/Qukeys.h @@ -202,7 +202,10 @@ class Qukeys : public kaleidoscope::Plugin { uint8_t minimum_prior_interval_{75}; // Timestamp of the keypress event immediately prior to the queue head event. - uint16_t prior_keypress_timestamp_{0}; + // The initial value is 256 to ensure that it won't trigger an error if a + // qukey is pressed before `minimum_prior_interval_` milliseconds after the + // keyboard powers on, and that value can only be as high as 255. + uint16_t prior_keypress_timestamp_{256}; // This is a guard against re-processing events when qukeys flushes them from // its event queue. We can't just use an "injected" key state flag, because