How to make key bind to open and close the menu?

I came up with this code that opens the menu:


	local FKeyMenus = {
		KEY_F4 = phm_1;
		KEY_C = phm_1;
	};
	hook.Add( "PlayerBindPress", "PlayerBindPressFKeyMenus", function( _p, _bind, _pressed )
		local _key = "KEY_" .. string.upper( input.LookupBinding( _bind ) );
		local _func = FKeyMenus[ _key ];
		if ( _func ) then 
			_func( LocalPlayer() );
		end
	end); 

I want to make that first time you press KEY_C or KEY_F4 menu opens, second time when menu is open and you press the KEY_ it will close the menu.