GetPlayerKeys

From SA-MP Wiki

(Difference between revisions)
Jump to: navigation, search
Revision as of 21:57, 7 December 2016
OstGot (Talk | contribs)

← Previous diff
Current revision
OstGot (Talk | contribs)

Line 9: Line 9:
{{Param|leftright|Left/right state.}} {{Param|leftright|Left/right state.}}
-{{NoReturn}}+{{Return|This function does not return any specific values.
 +* The keys are stored in the specified variables.}}
{{Notes2| {{Notes2|

Current revision



Description:

Check which keys a player is pressing.


Parameters:
(playerid, &keys, &updown, &leftright)
playeridThe ID of the player to get the keys of.
keysA set of bits containing the player's key states. This value is what is called a bit mask. Click here for a list of keys.
updownUp/down state.
leftrightLeft/right state.


Return Values:

This function does not return any specific values.
  • The keys are stored in the specified variables.


Image:32px-Circle-style-warning.png

Important
Notes

  • Only the FUNCTION of keys can be detected; not actual keys. For example, it is not possible to detect if a player presses SPACE, but you can detect if they press SPRINT (which can be mapped (assigned/binded) to ANY key (but is space by default)).
  • As of update 0.3.7, the keys "A" and "D" are not recognized when in a vehicle. However, keys "W" and "S" can be detected with the "keys" parameter.


The following example shows how you can regularly check the up/down/left/right values using OnPlayerUpdate.

Example Usage:

public OnPlayerUpdate(playerid)
{
    new Keys,ud,lr;
    GetPlayerKeys(playerid,Keys,ud,lr);
 
    if(ud == KEY_UP) SendClientMessage(playerid, -1, "UP");
    else if(ud == KEY_DOWN) SendClientMessage(playerid, -1, "DOWN");
 
    if(lr == KEY_LEFT) SendClientMessage(playerid, -1, "LEFT");
    else if(lr == KEY_RIGHT) SendClientMessage(playerid, -1, "RIGHT");
 
    return 1;
}

For a full list of all available keys, see here.

Related Callbacks

The following callbacks might be useful as well, as they are related to this callback in one way or another.

Personal tools