Garry's Mod Wiki

Player:KeyDown

  boolean Player:KeyDown( number key )

Description

Returns whether a key is down. This is not networked to other players, meaning only the local client can see the keys they are pressing.

Arguments

1 number key
The key, see IN enum

Returns

1 boolean
whether the key is down or not.

Example

Prints whenever the first player is holding +forward key (w on QWERTY keyboards).

hook.Add( "Tick", "KeyDown_Test", function() if ( Entity( 1 ):KeyDown( IN_FORWARD ) ) then print( "Player is pressing forward!" ) end end )
Output:
Player is pressing forward! Player is pressing forward! Player is pressing forward! Player is pressing forward!