Unfortunately I’m not working with InputMaps, but rather with InputEventMouse events directly.
How I’m currently set up is something like this:
I have a node right below the root that manages the emulated input like so
extends Node2D
var captured_events: Array[InputEventMouse]
func _ready():
Input.use_accumulated_input = false
func _input(event):
if event is InputEventMouse and event.device != -2:
var new_event: InputEventMouse = event.duplicate()
new_event.position = Vector2(100, 100)
new_event.device = -2
captured_events.append(new_event)
get_viewport().set_input_as_handled()
func _process(delta):
if !captured_events.is_empty():
for event in captured_events:
Input.parse_input_event(event)
captured_events.clear()
Now, this example is not very useful, all it does is grab the mouse events, change their device and and simply move them to (100, 100)
, in my current project they would be moved to where a simulated cursor would be, but this should be enough for demonstration purposes.
new_event.device
being set to -2
is simply to avoid infinite recursion.
This works just fine, if I place a button where the events are being moved to, I can click it remotely, and clicking on a button that’s not in the correct position will not respond to mouse inputs, so it seems like mouse inputs are now ignored anywhere but on (100, 100)
Problem arises with things like the PopupMenu
, the code above will let the popup menu appear on right click on a LineEdit
node, for example, but interacting with the menu itself will still have to be done with the system cursor, otherwise the menu will simply stay unresponsive.
I am aware that popup menus are different windows, and to mitigate that I tried this:
Inside the LineEdit
func _ready():
get_menu().window_input.connect(parent._input) #parent holds the input logic above
This, at least, fixes the “fake mouse” not even hovering over the menu options, they will darken where the input script is sending events.
However, selecting an option will still be done with the mouse itself, matter of fact, the “fake mouse” will not even cause a on hover effect unless the real mouse is moving to begin with.
So I thought that maybe, somehow, completely disabling the real mouse input except for the main node that creates the simulated mouse events would help, since the real mouse events are still being sent and could be handled by any node that implements _input(event)
, which is undesirable since I don’t plan on using the real inputs for anything other than handling my virtual cursor, they just cause undesired effects and bugs.
Hope this was descriptive enough, I’m not too well versed in godot yet.