Garry's Mod Wiki

Player:KeyPressed

  boolean Player:KeyPressed( number key )

Description

Gets whether a key was just pressed this tick.

Arguments

1 number key
Corresponds to an Enums/IN

Returns

1 boolean
Was pressed or not

Example

Prints whenever the first player first starts pressing +forward key (w on QWERTY keyboards).

hook.Add( "Tick", "CheckPlayer1Forward", function() if Entity( 1 ):KeyPressed( IN_FORWARD ) then print( "Player1 just started moving forward!" ) end end )