You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-17 14:11:06 +00:00
Add Input.is_anything_pressed method
This commit is contained in:
@@ -90,6 +90,7 @@ Input::MouseMode Input::get_mouse_mode() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Input::_bind_methods() {
|
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_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_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_mouse_button_pressed", "button"), &Input::is_mouse_button_pressed);
|
||||||
@@ -218,6 +219,19 @@ Input::VelocityTrack::VelocityTrack() {
|
|||||||
reset();
|
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 {
|
bool Input::is_key_pressed(Key p_keycode) const {
|
||||||
_THREAD_SAFE_METHOD_
|
_THREAD_SAFE_METHOD_
|
||||||
return keys_pressed.has(p_keycode);
|
return keys_pressed.has(p_keycode);
|
||||||
|
|||||||
@@ -242,6 +242,7 @@ public:
|
|||||||
|
|
||||||
static Input *get_singleton();
|
static Input *get_singleton();
|
||||||
|
|
||||||
|
bool is_anything_pressed() const;
|
||||||
bool is_key_pressed(Key p_keycode) const;
|
bool is_key_pressed(Key p_keycode) const;
|
||||||
bool is_physical_key_pressed(Key p_keycode) const;
|
bool is_physical_key_pressed(Key p_keycode) const;
|
||||||
bool is_mouse_button_pressed(MouseButton p_button) const;
|
bool is_mouse_button_pressed(MouseButton p_button) const;
|
||||||
|
|||||||
@@ -209,6 +209,12 @@
|
|||||||
[b]Note:[/b] Due to keyboard ghosting, [method is_action_pressed] may return [code]false[/code] even if one of the action's keys is pressed. See [url=$DOCS_URL/tutorials/inputs/input_examples.html#keyboard-events]Input examples[/url] in the documentation for more information.
|
[b]Note:[/b] Due to keyboard ghosting, [method is_action_pressed] may return [code]false[/code] even if one of the action's keys is pressed. See [url=$DOCS_URL/tutorials/inputs/input_examples.html#keyboard-events]Input examples[/url] in the documentation for more information.
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
|
<method name="is_anything_pressed" qualifiers="const">
|
||||||
|
<return type="bool" />
|
||||||
|
<description>
|
||||||
|
Returns [code]true[/code] if any action, key, joypad button, or mouse button is being pressed. This will also return [code]true[/code] if any action is simulated via code by calling [method action_press].
|
||||||
|
</description>
|
||||||
|
</method>
|
||||||
<method name="is_joy_button_pressed" qualifiers="const">
|
<method name="is_joy_button_pressed" qualifiers="const">
|
||||||
<return type="bool" />
|
<return type="bool" />
|
||||||
<argument index="0" name="device" type="int" />
|
<argument index="0" name="device" type="int" />
|
||||||
|
|||||||
Reference in New Issue
Block a user