Get mouse position each frame?

Place to get help with not working mods / modding interface.
Gizzmohammer
Inserter
Inserter
Posts: 23
Joined: Wed May 07, 2025 1:55 am
Contact:

Get mouse position each frame?

Post 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!
User avatar
Osmo
Fast Inserter
Fast Inserter
Posts: 204
Joined: Wed Oct 23, 2024 12:08 pm
Contact:

Re: Get mouse position each frame?

Post 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
Post Reply

Return to “Modding help”