EventHandlerResult TopsyTurvy::onKeyswitchEvent(Key &mapped_key, byte row, byte col, uint8_t key_state) { if (mapped_key == Key_LeftShift || mapped_key == Key_RightShift) { is_shifted_ = keyIsPressed(key_state); if (is_active_) return EventHandlerResult::EVENT_CONSUMED; } if (mapped_key < ranges::TT_FIRST || mapped_key > ranges::TT_LAST) { if (keyToggledOn(key_state) && (mapped_key < Key_LeftControl || mapped_key > Key_RightGui)) { last_pressed_position_ = row * COLS + col; } return EventHandlerResult::OK; } is_active_ = keyIsPressed(key_state); if (keyToggledOn(key_state)) { last_pressed_position_ = row * COLS + col; } else { if (last_pressed_position_ != row * COLS + col) { return EventHandlerResult::EVENT_CONSUMED; } } mapped_key.raw = mapped_key.raw - ranges::TT_FIRST; // invert the shift state if (!is_shifted_) { mapped_key.flags |= SHIFT_HELD; return EventHandlerResult::OK; } if (keyIsPressed(key_state)) { hid::releaseKey(Key_LeftShift); hid::releaseKey(Key_RightShift); return EventHandlerResult::OK; } return EventHandlerResult::EVENT_CONSUMED; }
EventHandlerResult GeminiPR::onKeyswitchEvent(Key &mapped_key, byte row, byte col, uint8_t keyState) { if (mapped_key < geminipr::START || mapped_key > geminipr::END) return EventHandlerResult::OK; if (keyToggledOn(keyState)) { uint8_t key = mapped_key.raw - geminipr::START; ++keys_held_; state_[key / 7] |= 1 << (6 - (key % 7)); } else if (keyToggledOff(keyState)) { --keys_held_; if (keys_held_ == 0) { state_[0] |= 0x80; Serial.write(state_, sizeof(state_)); memset(state_, 0, sizeof(state_)); } } return EventHandlerResult::EVENT_CONSUMED; }