Regarding character menus, an easy way to run a function when a menu opens or closes is to bind to the handler of the menu categories (the top icons bar when you open a menu)
Code:
ZO_PreHookHandler(ZO_MainMenuCategoryBar, "OnShow", function()
end)
ZO_PreHookHandler(ZO_MainMenuCategoryBar, "OnHide", function()
end)