# CFX::REGISTER_KEY_MAPPING

- **Hash:** `0xD7664FD1`
- **Namespace:** CFX
- **Runtime name (Lua/JS):** `RegisterKeyMapping`
- **Side:** client (Cfx runtime native)
- **Name status:** official
- **Documentation:** described with examples
- **URL:** https://natives.borderlinerp.com/natives/CFX/REGISTER_KEY_MAPPING

## Signature

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

## Parameters

- `commandString` (`char*`) — The command to execute, and the identifier of the binding.
- `description` (`char*`) — A description for in the settings menu.
- `defaultMapper` (`char*`) — The [mapper ID](https://docs.fivem.net/docs/game-references/input-mapper-parameter-ids/) to use for the default binding, e.g. `keyboard`.
- `defaultParameter` (`char*`) — The [IO parameter ID](https://docs.fivem.net/docs/game-references/input-mapper-parameter-ids/) to use for the default binding, e.g. `f3`.

## Returns

`void`

## Description

*Source: Cfx.re native reference*

Registers a key mapping for the current resource.

See the related [cookbook post](https://cookbook.fivem.net/2020/01/06/using-the-new-console-key-bindings/) 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

```lua
RegisterKeyMapping(commandString, description, defaultMapper, defaultParameter)

-- always available, by hash
Citizen.InvokeNative(0xd7664fd1, commandString, description, defaultMapper, defaultParameter)
```

### JavaScript

```js
RegisterKeyMapping(commandString, description, defaultMapper, defaultParameter);

// by hash
Citizen.invokeNative('0xd7664fd1', commandString, description, defaultMapper, defaultParameter);
```

### C#

```csharp
Function.Call((Hash)0xd7664fd1, commandString, description, defaultMapper, defaultParameter);
```

## Examples

*Source: Cfx.re native reference*

```lua
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.*
