When developing for FiveM, understanding controls is essential. Controls allow you to detect player input—such as pressing keys, using the mouse, or interacting with a controller—and respond with custom actions in your scripts. Whether you’re creating roleplay commands, mini-games, or custom interactions, mastering controls is a core skill for any FiveM developer.
In this post, we’ll cover:
- What controls are in FiveM
- Common control types and key mappings
- How to detect and respond to controls in scripts
- Best practices for working with controls
What Are Controls in FiveM?
In FiveM, controls are inputs from the player’s device. These include:
- Keyboard keys (e.g., E, F, H)
- Mouse buttons (e.g., left-click, right-click)
- Gamepad buttons (e.g., A, B, X, Y on Xbox controllers)
Controls are handled using native functions in FiveM scripts, allowing you to trigger events, interact with peds, vehicles, objects, and even your server UI.
Detecting Controls in Scripts
The most commonly used functions for detecting controls are:
IsControlPressed– Checks if a control is currently being held down.IsControlJustPressed– Checks if a control was pressed just once.IsControlReleased– Checks if a control was released.
Example: Detecting a Key Press
Citizen.CreateThread(function()
while true do
Citizen.Wait(0) -- Loop every frame
if IsControlJustPressed(1, 51) then -- 51 is the "E" key
print("Player pressed E!")
end
end
end)
In this example, when the player presses E, the script prints a message. You could easily replace this with actions like opening a shop, starting a job, or interacting with a ped.
Common Control Mappings
Controls in FiveM are defined by control IDs. Here are some frequently used ones:
| Action | Control ID | Description |
|---|---|---|
| E | 51 | Interaction key |
| F | 23 | Enter/exit vehicle or special action |
| SPACE | 22 | Jump |
| LEFT CTRL | 36 | Sprint / crouch modifier |
| LEFT MOUSE | 24 | Fire / primary action |
| RIGHT MOUSE | 25 | Aim / secondary action |
| G | 47 | Drop weapon or custom action |
A full list of controls can be found in the FiveM Native Reference.
Practical Uses of Controls
Controls are essential for creating interactive features in FiveM:
- Job interactions – Press E to start deliveries, open menus, or interact with NPCs.
- Custom game mechanics – Trigger abilities, mini-games, or special actions.
- Vehicle and weapon control – Detect when players enter vehicles, aim, or shoot.
- UI interaction – Open inventories, maps, or custom interfaces with a key press.
By combining controls with events, you can build responsive, immersive gameplay experiences.
Best Practices for Controls
- Avoid conflicts – Use keys that don’t interfere with default GTA V actions.
- Use custom control groups – Organize inputs to handle multiple devices (keyboard, mouse, controller).
- Debounce actions – Prevent multiple triggers from a single key press unless intentional.
- Provide feedback – Show notifications or UI hints when a key press triggers an action.
In our Learn FiveM Development course, you’ll practice using controls through projects and challenges—like opening custom menus, interacting with NPCs, or triggering server events—so you gain real-world experience handling player input.
