There are two separate issues here:
-
One - "cannot reach it with the left-mouse click, I still can switch the state of the button with the 'F' key"
This seem to be an intentional extra check for longer reach to toggle buttons with the mod keybind - 15 tiles.
Probably a good idea for such a simple control element, but should probably have an option for range, and be documented as not-a-bug.
-
Another one - "long distance activation with inventory shortcut in map mode".
This looks like a bug, where on_gui_opened doesn't check which gui it is, and replaces inventory with a button flip.
I do like this behavior though, as indeed flipping buttons from the map is really nice, even if looks a bit cheaty.
I think easy fix for both is to simply add "switch button range" mod setting and check that in both cases.
I.e. if you prefer buttons to be accessible from anywhere, just put that up to 9999, and if it feels like a cheat, then set it to 0 and let range check fallback to default player.character.can_reach_entity().
Plus mention all this in a mod description, so it won't be a surprise. Will implement that in 0.1.14, I guess.