Only responding to key presses when in-game

I need a menu to appear when a player presses the i key, which works. However, it also appears when the player is typing a chat message or is typing something in the console. I solved the issue when using the chatbox with:
[lua]function GM:StartChat()
self.InputEnabled = false

function GM:FinishChat()
self.InputEnabled = true
And I tried this for the menu and console:
[lua]function GM:PlayerBindPress( ply, bind, pressed )
if ( string.find( bind, “toggleconsole” ) or string.find( bind, “cancelselect” ) ) then
print( “Menu or console opened!” )
But it seems PlayerBindPress isn’t called when those binds are used. Is there any other way to solve this?

I hear there’s a drawing hook that does not get called when in the menu, but I forget which. It’s hacky but it would work.

Oh yes, HUDPaint is only called when not in the menu. I forgot about that, thanks :).