GM/KeyPress

From Garry's Mod
(Difference between revisions)
Jump to: navigation, search
(HidePredictionWarning)
Line 5: Line 5:
 
|Realm=Shared
 
|Realm=Shared
 
|Predicted=No
 
|Predicted=No
|HidePredictionWarning=No
 
|Name=KeyPress
 
|Parent=GM
 
 
}}
 
}}
 
{{Arg
 
{{Arg
Line 26: Line 23:
 
end
 
end
 
end )
 
end )
|Output="hi" in console
+
|OutputFixedWidth=Fixed width
 +
|Output=hi
 
}}
 
}}
 
{{Example
 
{{Example

Revision as of 02:28, 4 March 2017

 GM:KeyPress( )

Contents

Description

Called whenever a player pressed a key included within the IN keys.

WARNING

It seems that ParticleEffects created serverside from this hook will not be networked to the client, meaning they will not see the effects.

Arguments

Player ply

The player pressing the key. If running client-side, this will always be LocalPlayer

Arguments

number key

The key that the player pressed using IN_ Enums.

Examples

Example

"hi" will be printed to the console when the player presses the IN_USE (E) key.

hook.Add( "KeyPress", "keypress_use_hi", function( ply, key )
	if ( key == IN_USE ) then
		print( "hi" )
	end
end )

Output:

hi

Examples

Example

When a player tries to jump, they will be shot straight up in the air.

hook.Add( "KeyPress", "keypress_jump_super", function( ply, key )
    if ( key == IN_JUMP ) then
        ply:SetVelocity( ply:GetVelocity() + Vector( 0, 0, 1000 ) )
    end
end )


Personal tools
Navigation