Update testcases: events/keyboard-state/release-cleared

Signed-off-by: Michael Richters <gedankenexperimenter@gmail.com>
pull/1024/head
Michael Richters 4 years ago
parent a2f720e365
commit f13e08c77a
No known key found for this signature in database
GPG Key ID: 1288FD13E4EEF0C0

@ -64,16 +64,16 @@ namespace plugin {
class ConvertXtoY : public kaleidoscope::Plugin { class ConvertXtoY : public kaleidoscope::Plugin {
public: public:
EventHandlerResult onKeyswitchEvent(Key &key, KeyAddr key_addr, uint8_t key_state) { EventHandlerResult onKeyEvent(KeyEvent &event) {
if (keyToggledOn(key_state)) { if (keyToggledOn(event.state)) {
if (key == Key_X) if (event.key == Key_X)
key = Key_Y; event.key = Key_Y;
} }
// It should be impossible to get a `Key_X` at this point, because the // It should be impossible to get a `Key_X` at this point, because the
// previous block changes any `Key_X` to `Key_Y`, which results in the // previous block changes any `Key_X` to `Key_Y`, which results in the
// active keys cache storing that value. On subsequent cycles (while the key // active keys cache storing that value. On subsequent cycles (while the key
// is still pressed), the `key` value should be `Key_Y`. // is still pressed), the `key` value should be `Key_Y`.
if (keyIsPressed(key_state) && key == Key_X) { if (keyIsPressed(event.state) && event.key == Key_X) {
std::cerr << "t=" << Runtime.millisAtCycleStart() << ": " std::cerr << "t=" << Runtime.millisAtCycleStart() << ": "
<< "Error: we shouldn't see a key with value `X`" << std::endl; << "Error: we shouldn't see a key with value `X`" << std::endl;
} }
@ -81,7 +81,7 @@ class ConvertXtoY : public kaleidoscope::Plugin {
// active keys cache entry should be cleared. If it's not, then a subsequent // active keys cache entry should be cleared. If it's not, then a subsequent
// press of the same key without the layer shift in effect will still result // press of the same key without the layer shift in effect will still result
// in `Key_Y` instead of `Key_A`. // in `Key_Y` instead of `Key_A`.
if (keyToggledOff(key_state) && (key == Key_Y)) { if (keyToggledOff(event.state) && (event.key == Key_Y)) {
return EventHandlerResult::EVENT_CONSUMED; return EventHandlerResult::EVENT_CONSUMED;
} }
return EventHandlerResult::OK; return EventHandlerResult::OK;

@ -7,24 +7,21 @@ KEYSWITCH LAYER_SHIFT 1 0
# Keyboard state array # Keyboard state array
NAME Keyboard state cleared NAME Keyboard state cleared
RUN 10 ms RUN 4 ms
PRESS A PRESS A
RUN 1 cycle RUN 1 cycle
EXPECT keyboard-report Key_A # Report should contain only `A` EXPECT keyboard-report Key_A # Report should contain only `A`
RUN 5 ms RUN 4 ms
RELEASE A RELEASE A
RUN 1 cycle RUN 1 cycle
EXPECT keyboard-report empty # Report should be empty EXPECT keyboard-report empty # Report should be empty
RUN 5 ms RUN 5 ms
# Press and hold `ShiftToLayer(1)`, changing the `A` key to `X` # Press and hold `ShiftToLayer(1)`, changing the `A` key to `X`
PRESS LAYER_SHIFT PRESS LAYER_SHIFT
RUN 5 ms
RUN 4 ms
# Press `X`, which gets converted to `Y` by the `ConvertXtoY` plugin defined in # Press `X`, which gets converted to `Y` by the `ConvertXtoY` plugin defined in
# the sketch. The plugin simply changes the value of the key, which causes it to # the sketch. The plugin simply changes the value of the key, which causes it to
# get set to `Key_Y` in the keyboard state array. # get set to `Key_Y` in the keyboard state array.
@ -37,23 +34,25 @@ RUN 5 ms
# Release the `X` key (on Layer 1), which has become a `Y` key in the keyboard # Release the `X` key (on Layer 1), which has become a `Y` key in the keyboard
# state array. This should clear its entry. # state array. This should clear its entry.
RELEASE A RELEASE A
RUN 1 cycle # No report is expected here, however, because the release should trigger the
EXPECT keyboard-report empty # Report should be empty # `ConvertXtoY` plugin to return `EVENT_CONSUMED`. The active keys cache should
# be updated, but there shouldn't be a report.
RUN 5 ms
RUN 4 ms
# Release `ShiftToLayer(1)`. This should restore the `A` key to its base layer # Release `ShiftToLayer(1)`. This should restore the `A` key to its base layer
# value on subsequent presses, unless the Macros key gets "stuck" in the # value on subsequent presses, unless the Macros key gets "stuck" in the
# keyboard state array because it returns `EVENT_CONSUMED`. # keyboard state array because it returns `EVENT_CONSUMED`.
RELEASE LAYER_SHIFT RELEASE LAYER_SHIFT
RUN 5 ms RUN 1 cycle
# Now we still don't expect a report, because pressing or releasing a
# layer-change key doesn't trigger a keyboard HID report.
RUN 4 ms
PRESS A PRESS A
RUN 1 cycle RUN 1 cycle
EXPECT keyboard-report Key_A # Report should contain only `A` EXPECT keyboard-report Key_A # Report should contain only `A`
RUN 5 ms RUN 4 ms
RELEASE A RELEASE A
RUN 1 cycle RUN 1 cycle
EXPECT keyboard-report empty # Report should be empty EXPECT keyboard-report empty # Report should be empty

Loading…
Cancel
Save