You can set which pages are displayed when 403 & 404 errors occurs (admin/settings/error-reporting).

I guess you can add a new page in your `hook_menu()`, then set this page as the 403 error callback. When your custom menu callback is hit, you know you're outputting the "access denied" page!

opi