I have the Ghost Mode mod installed, with the shortcut button shown on my toolbar. I have several other mods installed as well, some of which also have a shortcut button. There seems to be a problem where the Ghost Mode button toggles on and off, no matter which shortcut button is pressed. It seems that your code is intercepting button-press messages which are intended for other mods.
I have experimented a little, and I think I have found a solution. In your 'control.lua' file, find this section of code:
script.on_event(defines.events.on_lua_shortcut,
function(event)
local player = game.get_player(event.player_index)
toggle_ghost_mode(player)
end
)
and amend it like this:
script.on_event(defines.events.on_lua_shortcut,
function(event)
if event.prototype_name == "ghost_mode_toggle_shortcut" then
local player = game.get_player(event.player_index)
toggle_ghost_mode(player)
end
end
)
This should ensure that your code only responds to button presses which were specifically intended for the Ghost Mode mod.
(Sorry about the lack of indentation - sadly, it seems that these messages don't take any notice of tabs or leading spaces.)