From 2ec84fe2d888861d56ea03960da0d799bae64bcf Mon Sep 17 00:00:00 2001 From: "Christopher S. Corley" Date: Wed, 17 Jun 2020 21:39:27 -0400 Subject: [PATCH 1/3] Fix key injection when many pressed at once Signed-off-by: Christopher S. Corley --- src/kaleidoscope/plugin/SpaceCadet.cpp | 39 +++++++++++++++++++++----- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/src/kaleidoscope/plugin/SpaceCadet.cpp b/src/kaleidoscope/plugin/SpaceCadet.cpp index 1dc9c75f..4007be05 100644 --- a/src/kaleidoscope/plugin/SpaceCadet.cpp +++ b/src/kaleidoscope/plugin/SpaceCadet.cpp @@ -104,8 +104,9 @@ EventHandlerResult SpaceCadet::onKeyswitchEvent(Key &mapped_key, KeyAddr key_add //check to see if we found a valid key. Assume not valid. bool valid_key = false; + bool other_mapped_key_flagged = false; - //This will only set one key, and, if it isn't in our map, it clears everything for the non-pressed key + //Check the current map to see if any other key has been already flagged //Exit condition is if we reach the special SPACECADET_MAP_END sentinel for ( uint8_t i = 0 ; @@ -117,14 +118,38 @@ EventHandlerResult SpaceCadet::onKeyswitchEvent(Key &mapped_key, KeyAddr key_add ++i ) { - if (mapped_key == map[i].input) { - //The keypress was valid and a match. Mark it as flagged and reset the counter - map[i].flagged = true; - map[i].start_time = Runtime.millisAtCycleStart(); + if (map[i].flagged + && map[i].input != mapped_key) { + other_mapped_key_flagged = true; + break; + } + } - //yes, we found a valid key - valid_key = true; + //This will only set one key, and, if it isn't in our map, it clears everything for the non-pressed key + //Exit condition is if we reach the special SPACECADET_MAP_END sentinel + for ( + uint8_t i = 0 ; + !( + map[i].input == Key_NoKey + && map[i].output == Key_NoKey + && map[i].timeout == 0 + ) ; + ++i + ) { + if (mapped_key == map[i].input) { + //Only activate this as part of the mapping if there isn't already a + //key waiting for timeout. This allows us to return OK later and for + //this loop to inject all the other flagged keys + if (!other_mapped_key_flagged) + { + //The keypress was valid and a match. Mark it as flagged and reset the counter + map[i].flagged = true; + map[i].start_time = Runtime.millisAtCycleStart(); + + //yes, we found a valid key + valid_key = true; + } } else { //If the key entry we're looking at was flagged previously, add it to the //report before we do anything else (this handles the situation where we From 3242af3ce0d53876faedabcab7b0b1fe54d43856 Mon Sep 17 00:00:00 2001 From: "Christopher S. Corley" Date: Wed, 17 Jun 2020 22:22:17 -0400 Subject: [PATCH 2/3] Adjust indentation & brace to follow lint rules Signed-off-by: Christopher S. Corley --- src/kaleidoscope/plugin/SpaceCadet.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/kaleidoscope/plugin/SpaceCadet.cpp b/src/kaleidoscope/plugin/SpaceCadet.cpp index 4007be05..befca2c5 100644 --- a/src/kaleidoscope/plugin/SpaceCadet.cpp +++ b/src/kaleidoscope/plugin/SpaceCadet.cpp @@ -118,11 +118,11 @@ EventHandlerResult SpaceCadet::onKeyswitchEvent(Key &mapped_key, KeyAddr key_add ++i ) { - if (map[i].flagged - && map[i].input != mapped_key) { - other_mapped_key_flagged = true; - break; - } + if (map[i].flagged + && map[i].input != mapped_key) { + other_mapped_key_flagged = true; + break; + } } //This will only set one key, and, if it isn't in our map, it clears everything for the non-pressed key @@ -141,8 +141,7 @@ EventHandlerResult SpaceCadet::onKeyswitchEvent(Key &mapped_key, KeyAddr key_add //Only activate this as part of the mapping if there isn't already a //key waiting for timeout. This allows us to return OK later and for //this loop to inject all the other flagged keys - if (!other_mapped_key_flagged) - { + if (!other_mapped_key_flagged) { //The keypress was valid and a match. Mark it as flagged and reset the counter map[i].flagged = true; map[i].start_time = Runtime.millisAtCycleStart(); From 918c09fa15e6b7435ad2f54c573a907121d328e0 Mon Sep 17 00:00:00 2001 From: "Christopher S. Corley" Date: Wed, 17 Jun 2020 22:47:29 -0400 Subject: [PATCH 3/3] More indention fixes for linter Signed-off-by: Christopher S. Corley --- src/kaleidoscope/plugin/SpaceCadet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/kaleidoscope/plugin/SpaceCadet.cpp b/src/kaleidoscope/plugin/SpaceCadet.cpp index befca2c5..0f30c165 100644 --- a/src/kaleidoscope/plugin/SpaceCadet.cpp +++ b/src/kaleidoscope/plugin/SpaceCadet.cpp @@ -119,7 +119,7 @@ EventHandlerResult SpaceCadet::onKeyswitchEvent(Key &mapped_key, KeyAddr key_add ) { if (map[i].flagged - && map[i].input != mapped_key) { + && map[i].input != mapped_key) { other_mapped_key_flagged = true; break; }