You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2026-01-05 19:31:35 +00:00
Add Input.is_physical_key_pressed method.
(cherry picked from commit 9877d91c4a)
This commit is contained in:
@@ -76,6 +76,11 @@ bool InputDefault::is_key_pressed(int p_scancode) const {
|
||||
return keys_pressed.has(p_scancode);
|
||||
}
|
||||
|
||||
bool InputDefault::is_physical_key_pressed(int p_scancode) const {
|
||||
_THREAD_SAFE_METHOD_
|
||||
return physical_keys_pressed.has(p_scancode);
|
||||
}
|
||||
|
||||
bool InputDefault::is_mouse_button_pressed(int p_button) const {
|
||||
_THREAD_SAFE_METHOD_
|
||||
return (mouse_button_mask & (1 << (p_button - 1))) != 0;
|
||||
@@ -316,6 +321,13 @@ void InputDefault::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool
|
||||
keys_pressed.erase(k->get_scancode());
|
||||
}
|
||||
}
|
||||
if (k.is_valid() && !k->is_echo() && k->get_physical_scancode() != 0) {
|
||||
if (k->is_pressed()) {
|
||||
physical_keys_pressed.insert(k->get_physical_scancode());
|
||||
} else {
|
||||
physical_keys_pressed.erase(k->get_physical_scancode());
|
||||
}
|
||||
}
|
||||
|
||||
Ref<InputEventMouseButton> mb = p_event;
|
||||
|
||||
@@ -716,6 +728,7 @@ void InputDefault::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();
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@ class InputDefault : public Input {
|
||||
|
||||
int mouse_button_mask;
|
||||
|
||||
Set<int> physical_keys_pressed;
|
||||
Set<int> keys_pressed;
|
||||
Set<int> joy_buttons_pressed;
|
||||
Map<int, float> _joy_axis;
|
||||
@@ -220,6 +221,7 @@ protected:
|
||||
|
||||
public:
|
||||
virtual bool is_key_pressed(int p_scancode) const;
|
||||
virtual bool is_physical_key_pressed(int p_scancode) const;
|
||||
virtual bool is_mouse_button_pressed(int p_button) const;
|
||||
virtual bool is_joy_button_pressed(int p_device, int p_button) const;
|
||||
virtual bool is_action_pressed(const StringName &p_action, bool p_exact = false) const;
|
||||
|
||||
Reference in New Issue
Block a user