Chat command to a keybind

Is there anyway that you can take a simple /trunk command and bind that to a key some how? When I Ask this, I literally mean just press a key and it typed the /command for you.

Indeed, this is how keymappings works
https://cookbook.fivem.net/2020/01/06/using-the-new-console-key-bindings/

Citizen.CreateThread(function() 
while true do
Citizen.Wait(1)
    if IsControlJustPressed(controltype, controlnumber) then -- see https://docs.fivem.net/docs/game-references/controls/
        ExecuteCommand('trunk')
    end
end
end)

Use this in any client.lua

See the docs to choose the keybind. Good luck.

Like Sandacz mentioned here:

You can actually bind a keybinding that your client’s can change to a command (assuming it’s created using RegisterCommand). An example can be found below:

RegisterKeyMapping('trunk', 'Open / Close Your Trunk', 'keyboard', 'i') -- change i to whatever key you'd like to use by default.

People that join your server can then change the keybind in Settings → Keybindings → FiveM.

1 Like

i need help with something like this if anyone could help

What do you need?

Binding a key uses this native:

Use this native to register your command first:

These 2 should do exactly as whats described in OP’s question. You’d of course need to script the functionality of the command to make it do anything :slight_smile:

i have figured it out thank you