Garry's Mod Wiki

Revision Difference

GM:PlayerButtonDown#527337

<function name="PlayerButtonDown" parent="GM" type="hook"> <ishook>yes</ishook> <description>Called when a player presses a button. This will not be called if player has a panel opened with keyboard input enabled, use <page>PANEL:OnKeyCodePressed</page> instead.</description> <realm>Shared</realm> <predicted>Yes</predicted> <args> <arg name="ply" type="Player">Player who pressed the button</arg> <arg name="button" type="number">The button, see <page>Enums/BUTTON_CODE</page></arg> </args> </function> <example> <description>Create a hook when press F3 open Frame</description>⤶ <description>Prints the person who pressed the key.</description>⤶ <code> hook.Add("PlayerButtonDown", "Boop.", function(ply, button) if (button == KEY_F3) then⤶ if not IsFirstTimePredicted() then return end⤶ local frame = vgui.Create("DFrame")⤶ frame:SetSize(300, 250)⤶ frame:Center()⤶ frame:MakePopup()⤶ frame:SetTitle("Hey I'm G-Man !")⤶ end⤶ hook.Add( "PlayerButtonDown", "ButtonUpWikiExample", function( ply, button ) print( ply:Nick() .. " pressed " .. input.GetKeyName(button) )⤶ end) </code> </example>