diff --git a/core/input/input_event.cpp b/core/input/input_event.cpp index afc8d10c91..cf73f5efa6 100644 --- a/core/input/input_event.cpp +++ b/core/input/input_event.cpp @@ -131,6 +131,8 @@ void InputEvent::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::INT, "device"), "set_device", "get_device"); BIND_CONSTANT(DEVICE_ID_EMULATION); + BIND_CONSTANT(DEVICE_ID_KEYBOARD); + BIND_CONSTANT(DEVICE_ID_MOUSE); } /////////////////////////////////// @@ -662,6 +664,10 @@ void InputEventKey::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "echo"), "set_echo", "is_echo"); } +InputEventKey::InputEventKey() { + set_device(DEVICE_ID_KEYBOARD); +} + /////////////////////////////////// void InputEventMouse::set_button_mask(BitField p_mask) { @@ -704,6 +710,10 @@ void InputEventMouse::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "global_position", PROPERTY_HINT_NONE, "suffix:px"), "set_global_position", "get_global_position"); } +InputEventMouse::InputEventMouse() { + set_device(DEVICE_ID_MOUSE); +} + /////////////////////////////////// void InputEventMouseButton::set_factor(float p_factor) { diff --git a/core/input/input_event.h b/core/input/input_event.h index ea163230d3..2a59d5815d 100644 --- a/core/input/input_event.h +++ b/core/input/input_event.h @@ -63,6 +63,8 @@ protected: public: static constexpr int DEVICE_ID_EMULATION = -1; static constexpr int DEVICE_ID_INTERNAL = -2; + static constexpr int DEVICE_ID_KEYBOARD = 16; // IDs 0-15 are reserved for joypads. + static constexpr int DEVICE_ID_MOUSE = 32; // IDs 17-31 are reserved for multiple keyboard support in the future. void set_device(int p_device); int get_device() const; @@ -199,6 +201,8 @@ public: static Ref create_reference(Key p_keycode_with_modifier_masks, bool p_physical = false); InputEventType get_type() const final override { return InputEventType::KEY; } + + InputEventKey(); }; class InputEventMouse : public InputEventWithModifiers { @@ -221,6 +225,8 @@ public: void set_global_position(const Vector2 &p_global_pos); Vector2 get_global_position() const; + + InputEventMouse(); }; class InputEventMouseButton : public InputEventMouse { diff --git a/doc/classes/InputEvent.xml b/doc/classes/InputEvent.xml index e4ead0e8c5..584b31f8fa 100644 --- a/doc/classes/InputEvent.xml +++ b/doc/classes/InputEvent.xml @@ -126,5 +126,11 @@ Device ID used for emulated mouse input from a touchscreen, or for emulated touch input from a mouse. This can be used to distinguish emulated mouse input from physical mouse input, or emulated touch input from physical touch input. + + Device ID used for input from a keyboard. This can be used to distinguish keyboard input events from joypad input events. + + + Device ID used for input from a mouse. This can be used to distinguish mouse input events from joypad input events. + diff --git a/doc/classes/InputEventGesture.xml b/doc/classes/InputEventGesture.xml index 2cf133911b..247db8ac00 100644 --- a/doc/classes/InputEventGesture.xml +++ b/doc/classes/InputEventGesture.xml @@ -10,6 +10,7 @@ $DOCS_URL/tutorials/inputs/inputevent.html + The local gesture position relative to the [Viewport]. If used in [method Control._gui_input], the position is relative to the current [Control] that received this gesture. diff --git a/doc/classes/InputEventMouse.xml b/doc/classes/InputEventMouse.xml index b6f77b4f0c..276be683b9 100644 --- a/doc/classes/InputEventMouse.xml +++ b/doc/classes/InputEventMouse.xml @@ -13,6 +13,7 @@ The mouse button mask identifier, one of or a bitwise combination of the [enum MouseButton] button masks. + When received in [method Node._input] or [method Node._unhandled_input], returns the mouse's position in the root [Viewport] using the coordinate system of the root [Viewport]. When received in [method Control._gui_input], returns the mouse's position in the [CanvasLayer] that the [Control] is in using the coordinate system of the [CanvasLayer]. diff --git a/doc/classes/InputEventWithModifiers.xml b/doc/classes/InputEventWithModifiers.xml index 1434f34115..e348948b1f 100644 --- a/doc/classes/InputEventWithModifiers.xml +++ b/doc/classes/InputEventWithModifiers.xml @@ -35,6 +35,7 @@ State of the [kbd]Ctrl[/kbd] modifier. + State of the [kbd]Meta[/kbd] modifier. On Windows and Linux, this represents the Windows key (sometimes called "meta" or "super" on Linux). On macOS, this represents the Command key.