Add Input.is_physical_key_pressed method.
(cherry picked from commit 9877d91c4a
)
This commit is contained in:
parent
420ec1f84a
commit
2ef2879d7b
5 changed files with 24 additions and 0 deletions
|
@ -55,6 +55,7 @@ Input::MouseMode Input::get_mouse_mode() const {
|
||||||
|
|
||||||
void Input::_bind_methods() {
|
void Input::_bind_methods() {
|
||||||
ClassDB::bind_method(D_METHOD("is_key_pressed", "scancode"), &Input::is_key_pressed);
|
ClassDB::bind_method(D_METHOD("is_key_pressed", "scancode"), &Input::is_key_pressed);
|
||||||
|
ClassDB::bind_method(D_METHOD("is_physical_key_pressed", "scancode"), &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);
|
||||||
ClassDB::bind_method(D_METHOD("is_joy_button_pressed", "device", "button"), &Input::is_joy_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"), &Input::is_action_pressed, DEFVAL(false));
|
ClassDB::bind_method(D_METHOD("is_action_pressed", "action", "exact"), &Input::is_action_pressed, DEFVAL(false));
|
||||||
|
|
|
@ -79,6 +79,7 @@ public:
|
||||||
static Input *get_singleton();
|
static Input *get_singleton();
|
||||||
|
|
||||||
virtual bool is_key_pressed(int p_scancode) const = 0;
|
virtual bool is_key_pressed(int p_scancode) const = 0;
|
||||||
|
virtual bool is_physical_key_pressed(int p_scancode) const = 0;
|
||||||
virtual bool is_mouse_button_pressed(int p_button) const = 0;
|
virtual bool is_mouse_button_pressed(int p_button) const = 0;
|
||||||
virtual bool is_joy_button_pressed(int p_device, int p_button) const = 0;
|
virtual bool is_joy_button_pressed(int p_device, int p_button) const = 0;
|
||||||
virtual bool is_action_pressed(const StringName &p_action, bool p_exact = false) const = 0;
|
virtual bool is_action_pressed(const StringName &p_action, bool p_exact = false) const = 0;
|
||||||
|
|
|
@ -264,6 +264,13 @@
|
||||||
Returns [code]true[/code] if you are pressing the mouse button specified with [enum ButtonList].
|
Returns [code]true[/code] if you are pressing the mouse button specified with [enum ButtonList].
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
|
<method name="is_physical_key_pressed" qualifiers="const">
|
||||||
|
<return type="bool" />
|
||||||
|
<argument index="0" name="scancode" type="int" />
|
||||||
|
<description>
|
||||||
|
Returns [code]true[/code] if you are pressing the key in the physical location on the 101/102-key US QWERTY keyboard. You can pass a [enum KeyList] constant.
|
||||||
|
</description>
|
||||||
|
</method>
|
||||||
<method name="joy_connection_changed">
|
<method name="joy_connection_changed">
|
||||||
<return type="void" />
|
<return type="void" />
|
||||||
<argument index="0" name="device" type="int" />
|
<argument index="0" name="device" type="int" />
|
||||||
|
|
|
@ -76,6 +76,11 @@ bool InputDefault::is_key_pressed(int p_scancode) const {
|
||||||
return keys_pressed.has(p_scancode);
|
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 {
|
bool InputDefault::is_mouse_button_pressed(int p_button) const {
|
||||||
_THREAD_SAFE_METHOD_
|
_THREAD_SAFE_METHOD_
|
||||||
return (mouse_button_mask & (1 << (p_button - 1))) != 0;
|
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());
|
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;
|
Ref<InputEventMouseButton> mb = p_event;
|
||||||
|
|
||||||
|
@ -716,6 +728,7 @@ void InputDefault::release_pressed_events() {
|
||||||
flush_buffered_events(); // this is needed to release actions strengths
|
flush_buffered_events(); // this is needed to release actions strengths
|
||||||
|
|
||||||
keys_pressed.clear();
|
keys_pressed.clear();
|
||||||
|
physical_keys_pressed.clear();
|
||||||
joy_buttons_pressed.clear();
|
joy_buttons_pressed.clear();
|
||||||
_joy_axis.clear();
|
_joy_axis.clear();
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,7 @@ class InputDefault : public Input {
|
||||||
|
|
||||||
int mouse_button_mask;
|
int mouse_button_mask;
|
||||||
|
|
||||||
|
Set<int> physical_keys_pressed;
|
||||||
Set<int> keys_pressed;
|
Set<int> keys_pressed;
|
||||||
Set<int> joy_buttons_pressed;
|
Set<int> joy_buttons_pressed;
|
||||||
Map<int, float> _joy_axis;
|
Map<int, float> _joy_axis;
|
||||||
|
@ -220,6 +221,7 @@ protected:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual bool is_key_pressed(int p_scancode) const;
|
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_mouse_button_pressed(int p_button) const;
|
||||||
virtual bool is_joy_button_pressed(int p_device, 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;
|
virtual bool is_action_pressed(const StringName &p_action, bool p_exact = false) const;
|
||||||
|
|
Loading…
Reference in a new issue