Skip to content

Commit

Permalink
Prevent key state vaIidation from resetting virtual key state on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
houmain committed Jul 14, 2024
1 parent 094150d commit f9c3363
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
6 changes: 6 additions & 0 deletions src/runtime/Key.h
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,12 @@ constexpr bool is_keyboard_key(Key key) {
!is_mouse_wheel(key));
}

constexpr bool is_device_key(Key key) {
return (is_keyboard_key(key) ||
is_mouse_button(key) ||
is_mouse_wheel(key));
}

constexpr bool is_action_key(Key key) {
return (key >= Key::first_action && key <= Key::last_action);
}
14 changes: 8 additions & 6 deletions src/runtime/Stage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ bool Stage::is_clear() const {
std::vector<Key> Stage::get_output_keys_down() const {
auto keys = std::vector<Key>{ };
for (const auto& output : m_output_down)
if (is_keyboard_key(output.key) || is_mouse_button(output.key))
if (is_device_key(output.key))
keys.push_back(output.key);
return keys;
}
Expand Down Expand Up @@ -329,13 +329,17 @@ void Stage::validate_state(const std::function<bool(Key)>& is_down) {

m_sequence.erase(
std::remove_if(begin(m_sequence), end(m_sequence),
[&](const KeyEvent& event) { return !is_down(event.key); }),
[&](const KeyEvent& event) {
return is_device_key(event.key) &&
!is_down(event.key);
}),
end(m_sequence));

m_output_down.erase(
std::remove_if(begin(m_output_down), end(m_output_down),
[&](const OutputDown& output) {
return !is_down(get_trigger_key(output.trigger));
return is_device_key(output.key) &&
!is_down(get_trigger_key(output.trigger));
}),
end(m_output_down));
}
Expand Down Expand Up @@ -426,9 +430,7 @@ bool Stage::is_physically_pressed(Key key) const {
void Stage::apply_input(const KeyEvent event, int device_index) {
assert(event.state == KeyState::Down ||
event.state == KeyState::Up);
assert(is_keyboard_key(event.key) ||
is_mouse_button(event.key) ||
is_mouse_wheel(event.key) ||
assert(is_device_key(event.key) ||
is_virtual_key(event.key) ||
event.key == Key::timeout);

Expand Down

0 comments on commit f9c3363

Please sign in to comment.