Detecting keypress within DFrame

It’s probably something simple that I’m overlooking but I’ve enabled SetKeyboardInputEnabled on the DFrame, RequestFocus( ), and MakePopup( ). I tried tying into OnEnter, PANEL:Think( ), and OnKeyPressed( ) with no results.

Here’s my Think. Essentially I have a scoreboard that I can hold TAB to open, and when I let go before 1/4 second is up it stays open as designed. If it’s held and released after 1/4 second, it stays open. I’d like to add functionality to close the panel if TAB is pressed within the panel.

[lua]function PANEL:Think( )
if ( CurTime( ) - SCOREBOARD_TIME_OPENED < SCOREBOARD_TIME_OPENED_TAP_DELAY ) then return; end
// KeyDown doesn’t detect in VGUI doesn’t detect
if ( LocalPlayer( ):KeyDown( IN_SCORE ) ) then
self:Remove( )
end

// This code crashes Garry's Mod when uncommented; CTD
-- if ( input.IsKeyDown( IN_SCORE ) ) then
	-- self:Remove( )
-- end

end[/lua]

Everything works as designed, but I can’t detect tab or other keys from within the DFrame. Probably something simple, but I can’t find any information on this in the wiki or on these forums through Google searches.

input.IsKeyDown() is probably your best bet, but in your commented code you’re using it wrong.

You’re passing an IN_Enum but the function is expecting a KEY_Enum. You can find the KEY_Enums here: http://wiki.garrysmod.com/page/Enums/KEY and documentation of the function here: http://wiki.garrysmod.com/page/input/IsKeyDown

I think this code will do what you want, or i hope you can adapt it to do what you want.



function PANEL:Think( )
	if ( CurTime( ) - SCOREBOARD_TIME_OPENED < SCOREBOARD_TIME_OPENED_TAP_DELAY ) then return; end

	if ( input.IsKeyDown( KEY_TAB ) ) then
		self:Remove( )
	end
end


Thanks!! It’s funny how the IN_ key caused my game to CTD, no warning/error anything.

I appreciate it!