Page 1 of 1

Get mouse position each frame?

Posted: Tue Dec 09, 2025 8:32 pm
by Gizzmohammer
I'm trying to create a line from an object to the mouse, and have it update each frame

I'm not sure the best way to get mouse position each frame.

The only way I've seen in the documentation is to use a custom input, but that will only activate when the button is first pressed
i.e: script.on_event("my-custom-input", function(event) local cursor_position = event.cursor_position end)

Is there any other way to get the mouse position?

Thanks!

Re: Get mouse position each frame?

Posted: Tue Dec 09, 2025 11:31 pm
by Osmo
There is no way to get mouse position apart from certain events as mouse position is not part of game state, and as such is not available to mods.
You can look at how https://mods.factorio.com/mod/Tapeline does it, which seems to be using a selection tool and area from event such as this https://lua-api.factorio.com/latest/eve ... ected_area