summaryrefslogtreecommitdiff
path: root/core/input/input.cpp
diff options
context:
space:
mode:
authorbruvzg <7645683+bruvzg@users.noreply.github.com>2021-11-23 11:14:19 +0200
committerbruvzg <7645683+bruvzg@users.noreply.github.com>2021-11-23 11:14:19 +0200
commit9877d91c4a573a7538c042f7f01b5c97e17dcd2d (patch)
tree1d374ab023c81c6c5f2c79168cdf81b4467b0533 /core/input/input.cpp
parent1e71cab79775137beade1d9f78c709a1a4f97cfc (diff)
Add Input.is_physical_key_pressed method.
Diffstat (limited to 'core/input/input.cpp')
-rw-r--r--core/input/input.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/core/input/input.cpp b/core/input/input.cpp
index 6fd8aca01b..d0144ca47f 100644
--- a/core/input/input.cpp
+++ b/core/input/input.cpp
@@ -91,6 +91,7 @@ Input::MouseMode Input::get_mouse_mode() const {
void Input::_bind_methods() {
ClassDB::bind_method(D_METHOD("is_key_pressed", "keycode"), &Input::is_key_pressed);
+ ClassDB::bind_method(D_METHOD("is_physical_key_pressed", "keycode"), &Input::is_physical_key_pressed);
ClassDB::bind_method(D_METHOD("is_mouse_button_pressed", "button"), &Input::is_mouse_button_pressed);
ClassDB::bind_method(D_METHOD("is_joy_button_pressed", "device", "button"), &Input::is_joy_button_pressed);
ClassDB::bind_method(D_METHOD("is_action_pressed", "action", "exact_match"), &Input::is_action_pressed, DEFVAL(false));
@@ -223,6 +224,11 @@ bool Input::is_key_pressed(Key p_keycode) const {
return keys_pressed.has(p_keycode);
}
+bool Input::is_physical_key_pressed(Key p_keycode) const {
+ _THREAD_SAFE_METHOD_
+ return physical_keys_pressed.has(p_keycode);
+}
+
bool Input::is_mouse_button_pressed(MouseButton p_button) const {
_THREAD_SAFE_METHOD_
return (mouse_button_mask & mouse_button_to_mask(p_button)) != MouseButton::NONE;
@@ -465,6 +471,13 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em
keys_pressed.erase(k->get_keycode());
}
}
+ if (k.is_valid() && !k->is_echo() && k->get_physical_keycode() != Key::NONE) {
+ if (k->is_pressed()) {
+ physical_keys_pressed.insert(k->get_physical_keycode());
+ } else {
+ physical_keys_pressed.erase(k->get_physical_keycode());
+ }
+ }
Ref<InputEventMouseButton> mb = p_event;
@@ -862,6 +875,7 @@ void Input::release_pressed_events() {
flush_buffered_events(); // this is needed to release actions strengths
keys_pressed.clear();
+ physical_keys_pressed.clear();
joy_buttons_pressed.clear();
_joy_axis.clear();