GetPlayerKeys

From SA-MP Wiki

Jump to: navigation, search


Check which keys a player is pressing.


Parameters:
(playerid, &keys, &updown, &leftright)
playeridThe ID of the player to detect the keys of.
keysA set of bits containing the player's key states. Click here for a list.
updownUp or Down value.
leftrightLeft or Right value.


ReturnsThis function doesn't return a specific value


Image:32px-Circle-style-warning.png Important Note: Only the FUNCTION of keys can be detected; not actual keys. You can not detect if a player presses space, but you can detect if they press sprint (which can be mapped (assigned) to ANY key, but is space by default)).


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

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 Keys.


Related Callbacks

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

Personal tools