Create GET_KEY_MAPPING

Hello!
I love using REGISTER_KEY_MAPPING, but there is one problem with it.

Currently I display key hints using NUI. Problem is, that there is currently no way to get, what key did user bind to specific action.

If there would be function char* GET_KEY_MAPPING( char* commandString) we could simply get the key and display it. So I would just do:

RegisterKeyMapping('+handsup', 'Hands Up', 'keyboard', 'i')
local registeredKey = GetKeyMapping("+handsup")
print("Press " .. registeredKey .. " to put your hands up!")

Would be really great, also, is possibility of binding multiple keys planned?

If you were using scaleform you can display it by getting the joaat hash of the command and then e.g. ~INPUT_C524BF85~

2 Likes

And so is there currently not any way to pass it to NUI? It would be really helpful :frowning:
Sice we prefer to use NUI

The same thing you’d do for normal keys (get instructional button) should work for the hash here.

It works great, thanks!

The problem i see is that if i bind more actions for the same key and then i just one, all others are removed.

For example if I bind 3 commands on key “E” and then edit one of them in settings to “Z”, two others are just removed. Is this just a GTA thing? Would be cool, if two others just stayed on “E”

Hm, might be a bug with the GTA menu integration. If you can consistently cause this across versions maybe post exact steps in #general-discussion:bug-reports so it can be tracked. :slight_smile:

Okay thanks, done: Mapped keys are removed when command with same key is changed - FiveM Discussion / Bug reports - Cfx.re Community

1 Like

Ha, nice. I was just trying to figure out a solution for this this week. Is this documented anywhere?

hi, can you show me an example to display the bind key in NUI?

EDIT:e.g
print(‘fishing_gs → eco_fishing_ngs’, GetControlInstructionalButton(0, 2907530946, 1))
print(‘fishing_sfl → eco_fishing_sfl’, GetControlInstructionalButton(0, 2285202028, 1))

I had to modify the command names so that the hash was above 2200000000
It didn’t return anything during this

You are doing it wrong. No matter the name of the function.

You need use this: FiveM Hash Generator
eco_fishing_ngs = ~INPUT_AD4D66C2~
fishing_gs = ~INPUT_19077CB2~

And this text you subtract ~INPUT_ and ~.

Then adds 0x at the beginning. (This is to be interpreted as a hexadecimal number)
The final result:
eco_fishing_ngs key = GetControlInstructionalButton(0, 0xAD4D66C2, 1)

Also say that if you change the name of the function (eco_fishing_ngs, RegisterKeyMapping is clear for this function, for all players. Because AD4D66C2 = eco_fishing_ngs)

If you like more information go to my post for this

Thank you, this is a very informative answer. So I can now use this function.