Garry's Mod Wiki

Revision Difference

Player:KeyDown#527829

<function name="KeyDown" parent="Player" type="classfunc"> <description>Gets whether a key is down. This is not networked to other players, meaning only the local client can see the keys they are pressing.</description> <realm>Shared</realm> <args> <arg name="key" type="number">The key, see <page>Enums/IN</page></arg> </args> <rets> <ret name="" type="boolean">isDown</ret>⤶ <ret name="" type="boolean">isDown ?</ret>⤶ </rets> </function> <example> <description>Prints whenever the first player is holding forward key</description>⤶ <description>Prints whenever the first player is holding <key>+FORWARD</key> key (<key>W</key> on QWERTY keyboards).</description>⤶ <code> hook.Add( "Tick", "KeyDown_Test", function() if ( Entity( 1 ):KeyDown( IN_FORWARD ) ) then print( "Player is pressing forward!" ) end end ) </code> <outputfixedwidth>Fixed width</outputfixedwidth>⤶ <output> ```⤶ Player is pressing forward! Player is pressing forward! Player is pressing forward! Player is pressing forward! ```⤶ </output> ⤶ </example></example>