# getControlState (Server)

> Tells whether a player is pressing a control, going by the keys their client last sent.

- **Platform**: MY Multiplayer (MYMP)
- **Kind**: Lua Function
- **Side**: Server
- **Category**: Controls
- **URL**: https://wiki.mymp.gg/en/getControlState-server
- **Counterpart**: Also exists on the client, with its own implementation: [getControlState (Client)](https://wiki.mymp.gg/en/getControlState-client.md)

## Syntax

```lua
bool getControlState(player thePlayer, string control)
```

## Parameters

| Name | Type | Description |
| --- | --- | --- |
| `thePlayer` | `player` | The player. |
| `control` | `string` | The control's name, case insensitive. |

## Returns

`true` if the control is pressed. `false` if it is not, if the server does not receive that control, if the element is not a player or if the control name does not exist.

Vehicle controls only count while the player is in a vehicle, and on-foot ones only outside.

## Example

```lua
setTimer(function()
    for _, player in ipairs(getElementsByType("player")) do
        if getControlState(player, "horn") then
            outputServerLog(getPlayerName(player) .. " is honking")
        end
    end
end, 1000, 0)
```

### Note

The server only receives some controls. On foot: `fire`, `forwards`, `backwards`, `left`, `right`, `enter_exit`, `jump`, `sprint`, `crouch`, `action`, `walk`, `aim_weapon`, `block` and `reload`. In a vehicle: `vehicle_fire`, `vehicle_secondary_fire`, `vehicle_left`, `vehicle_right`, `steer_forward`, `steer_back`, `accelerate`, `brake_reverse`, `horn`, `handbrake` and `enter_exit`. The others always give `false`.

## See also

- [setControlState (Server)](https://wiki.mymp.gg/en/setControlState-server.md): Presses or releases one of a player's controls as if it were a key. The order goes to their client, which applies it as setControlState on the local player.
- [isControlEnabled (Server)](https://wiki.mymp.gg/en/isControlEnabled-server.md): Tells whether one of a player's controls is on, going by what the server sent to their client.
- [getControlState (Client)](https://wiki.mymp.gg/en/getControlState-client.md): Tells whether one of a ped's controls is pressed, such as forwards, fire or accelerate.
