If you ONLY need to detect if someone got the main menu opened (the one at the left if you press ESC) I think you need to do it like you did with the explicit check for the scene / or a fragment.
Lua Code:
local function sceneChange(sceneName, oldState, newState)
if (newState == SCENE_SHOWN) then
-- do stuff
elseif (newState == SCENE_HIDDEN) then
-- do stuff
end
end
local scene = SCENE_MANAGER:GetScene("gameMenuInGame")
scene:RegisterCallback("StateChange", sceneChange)
Or directly use the global GAME_MENU_SCENE (
https://github.com/esoui/esoui/blob/...ngame.lua#L132) to register the StateChange callback function.
If you want to detect if ANY menu was opened (e.g. also if you open the inventory and the top bar menu is shown) you'd need to register a callback function to the HUD_SCENE and/or HUD_UI_SCENE 's "StateChange" like described here:
https://wiki.esoui.com/Scene_Manager:_On_scene_change