diff options
author | Andrii Doroshenko (Xrayez) <xrayez@gmail.com> | 2020-03-27 02:56:29 +0200 |
---|---|---|
committer | Andrii Doroshenko (Xrayez) <xrayez@gmail.com> | 2022-01-20 20:55:14 +0200 |
commit | 5d17fe7d0ff1864c7243303778b0733beb837992 (patch) | |
tree | 72b1ad06a456afe9a41920697da7560757f1c3a1 /core/input | |
parent | 8fc0dd9997c80059ec2b273e7004daa458d370ee (diff) |
Add `Input.is_anything_pressed` method
Diffstat (limited to 'core/input')
-rw-r--r-- | core/input/input.cpp | 14 | ||||
-rw-r--r-- | core/input/input.h | 1 |
2 files changed, 15 insertions, 0 deletions
diff --git a/core/input/input.cpp b/core/input/input.cpp index fa2f00bf8d..3ddb151f23 100644 --- a/core/input/input.cpp +++ b/core/input/input.cpp @@ -90,6 +90,7 @@ Input::MouseMode Input::get_mouse_mode() const { } void Input::_bind_methods() { + ClassDB::bind_method(D_METHOD("is_anything_pressed"), &Input::is_anything_pressed); 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); @@ -218,6 +219,19 @@ Input::VelocityTrack::VelocityTrack() { reset(); } +bool Input::is_anything_pressed() const { + _THREAD_SAFE_METHOD_ + + for (Map<StringName, Input::Action>::Element *E = action_state.front(); E; E = E->next()) { + if (E->get().pressed) { + return true; + } + } + return !keys_pressed.is_empty() || + !joy_buttons_pressed.is_empty() || + mouse_button_mask > MouseButton::NONE; +} + bool Input::is_key_pressed(Key p_keycode) const { _THREAD_SAFE_METHOD_ return keys_pressed.has(p_keycode); diff --git a/core/input/input.h b/core/input/input.h index e5ef31ab4f..80f260f30e 100644 --- a/core/input/input.h +++ b/core/input/input.h @@ -242,6 +242,7 @@ public: static Input *get_singleton(); + bool is_anything_pressed() const; bool is_key_pressed(Key p_keycode) const; bool is_physical_key_pressed(Key p_keycode) const; bool is_mouse_button_pressed(MouseButton p_button) const; |