RedM Natives

REGISTER_KEY_MAPPING

Registers a key mapping for the current resource.

Hash0xD7664FD1
Runtime nameRegisterKeyMapping
NamespaceCFX
SideClient
NameOfficial
Docs

Signature

void REGISTER_KEY_MAPPING(char* commandString, char* description, char* defaultMapper, char* defaultParameter);

Parameters

NameTypeDescription
commandStringchar*

The command to execute, and the identifier of the binding.

descriptionchar*

A description for in the settings menu.

defaultMapperchar*

The mapper ID to use for the default binding, e.g. keyboard.

defaultParameterchar*

The IO parameter ID to use for the default binding, e.g. f3.

Returns void

Description

Cfx.re native reference

Registers a key mapping for the current resource.

See the related cookbook post for more information.

Below you can find some examples on how to create these keybindings as well as the alternate keybinding syntax, which is preceded by ~! to indicate that it's an alternate key.

Usage

Lua
RegisterKeyMapping(commandString, description, defaultMapper, defaultParameter)

-- always works, by hash
Citizen.InvokeNative(0xd7664fd1, commandString, description, defaultMapper, defaultParameter)
JavaScript and C#
JavaScript
RegisterKeyMapping(commandString, description, defaultMapper, defaultParameter);

// by hash
Citizen.invokeNative('0xd7664fd1', commandString, description, defaultMapper, defaultParameter);
C#
Function.Call((Hash)0xd7664fd1, commandString, description, defaultMapper, defaultParameter);

Examples

LUA · Cfx.re native reference
local handsUp = false
CreateThread(function()
    while true do
        Wait(0)
        if handsUp then
            TaskHandsUp(PlayerPedId(), 250, PlayerPedId(), -1, true)
        end
    end
end)
RegisterCommand('+handsup', function()
    handsUp = true
end, false)
RegisterCommand('-handsup', function()
    handsUp = false
end, false)

RegisterKeyMapping('+handsup', 'Hands Up', 'keyboard', 'i')

-- Alternate keybinding syntax
RegisterKeyMapping('~!+handsup', 'Hands Up - Alternate Key', 'keyboard', 'o')

Sources

Cfx.re native reference

Something wrong or missing? Contribute a verified note — corrections ship through pull requests.