Key bindings
Key bindings
Section titled “Key bindings”MenuAPI handles all menu controls for you. On a keyboard it does that through FiveM key mappings, which
means every menu control shows up in the player’s own Settings, Key Bindings screen and they can change
it to whatever key they like. You do not have to write any code for this, it happens as soon as your resource
loads MenuAPI.dll.
A “key mapping” is FiveM’s built in system for rebindable keys. Your resource registers a named action with a default key, and from then on the player is in charge of which key actually triggers it. Their choice is saved on their own machine, so it sticks between sessions and between servers.
What gets registered
Section titled “What gets registered”Seven bindings, all on the keyboard.
| What it does | Shown in the settings as | Default key |
|---|---|---|
| Opens and closes the menu | Open / close menu | M |
| Moves up one item | Menu up | ↑ |
| Moves down one item | Menu down | ↓ |
| Moves left on lists and sliders, goes back on anything else | Menu left | ← |
| Moves right on lists and sliders, selects anything else | Menu right | → |
| Selects the highlighted item | Menu select | Enter |
| Goes back one menu, or closes the menu | Menu back | Backspace |
They are grouped under your resource’s name in the key bindings screen, so players can tell them apart from any other resource’s bindings.
Changing the default toggle key
Section titled “Changing the default toggle key”The key that opens the menu is the one a server owner is most likely to care about, so your resource can pick its own default instead of M:
public class MyMenus : IScript{ public MyMenus() { MenuController.MenuToggleKeyDefault = "F5"; }}Set it in your resource’s constructor. MenuAPI registers its key mappings one tick after it starts, specifically so this works no matter whether your script or MenuAPI’s was created first. Setting it later than that has no effect, because the mapping has already been registered by then.
The value is a keyboard input mapper parameter id,
the same sort of string as "M", "F5" or "HOME". If you leave it empty or null, M is used.
Only the toggle key can be changed this way. The navigation keys are left alone on purpose, since they are much less likely to clash with anything and players can rebind them themselves anyway.
The mouse
Section titled “The mouse”On top of the bindings above, MenuAPI also reads a few mouse inputs directly. These are fixed, they do not appear in the key bindings screen and they can not be changed or removed.
| Mouse input | What it does |
|---|---|
| Scroll wheel up | Moves up one item |
| Scroll wheel down | Moves down one item |
| Left click | Selects the highlighted item |
| Right click | Goes back one menu, or closes the menu |
Scrolling the wheel while holding TAB on foot is left alone, so the weapon wheel keeps working.
Controllers
Section titled “Controllers”Controller input is completely separate and is not rebindable. It still works the way it always has.
- Opening the menu: hold the back/select button (the interaction menu button) for 400ms. Set EnableMenuToggleKeyOnController to false to turn this off.
- Navigating: the d-pad and left stick move around, the accept button selects, and the cancel button goes back.
The reason it is left alone is that a controller’s buttons are already consistent across every game, so there is far less reason to let people move them around, and the 400ms hold on the toggle button is there on purpose so a quick tap does not open the menu by accident.
Command names
Section titled “Command names”Behind the scenes each binding is a console command, and FiveM command names are shared by every resource on the server. To make sure two resources that both ship MenuAPI never fight over the same names, the names are built from your resource’s own name, lowercased:
menuapi:<your-resource-name>:toggle+menuapi:<your-resource-name>:up+menuapi:<your-resource-name>:down+menuapi:<your-resource-name>:left+menuapi:<your-resource-name>:right+menuapi:<your-resource-name>:select+menuapi:<your-resource-name>:backThe + on most of them is FiveM’s way of saying “this one cares about being held down”: pressing the key
runs +command and letting go runs -command. That is how holding an arrow key keeps scrolling.
Instructional buttons
Section titled “Instructional buttons”The select and back hints drawn at the bottom of the screen follow the player’s own bindings automatically. If someone binds select to J, the hint shows J. On a controller the hints switch to the controller’s glyphs instead, the moment a controller is used.
You can change the text next to them, or hide them, per menu. See Instructional buttons.
