Hello there! Is that possible to have a native fx event such as onKeyPressed (I searched for other MP clients, and that event was available. why can’t we have this on FiveM?) so we can get rid of those loops which gonna mess up the performance just so to determine if the client pressed a button or not. I even tried to do such a thing in JS, but when the NUI focus is off, it doesn’t work. At least add a feature to bind functions to RegisterKeyMapping (but to be honest, it’s not really useful, I can’t bind a key two times on two different scripts, and for some of my users, those keys are registered by that native doesn’t work).
PLEASE add this!! . 90% of the loops are because of the keybinds 
God hates me, I hate Citizen.Wait(0)
Str8 FAX bro
I haven’t tried this out myself, just a brain storm… This might work, it might not either…
I atleast hope it gives you a little idea of how you could fix it.
btw; its all client-side
-- SNIPPED OUT BAD CODE THAT EVEN USES A KEY TABLE
-- for promoting bad practices
-- also, Wait(7)? wtf?
Yes, there is still an loop, but now you dont need to make a loop in every script to check if the key was pressed… Just a ‘cheap’ fix i guess?
I have something like this on one of my scripts with Citizen.Wait(10), and it’s consuming 3.5%. It’s not good
Are you guys all blind or so?
This was added like nearly a year ago and unlike many other things is even documented.
I have nothing to say you didn’t even bother your self reading the post!
Oh, also, why not report such as a reproable bug instead of requesting something that already exists?
Also, ‘binding a key two times on two different scripts’ works fine or is meant to work fine, ‘functions’ can be ‘bound’ using commands (and to hide them in chat, that’s a separate request again?), and ‘some of your users’ is so weasel-word-y that you still need to provide a repro.
Cool?
Maybe if you’d have structured your post to not be a single fucking paragraph it’d have been harder to miss.
Still doesn’t take away the fact that you’re requesting something which already exists in the form of RegisterKeyMapping, and that the ‘issues’ you mentioned would part be bugs and part be stuff you can easily wrap in a script yourself.
Hey, Mr. Cretin, here’s a way to solve those two issues in one fucking go, but of course you’ll be crying eternally and not being considerate at all and therefore I doubt you’ll report that alleged bug you’re having ever:
-- in some shared resource you might even call 'keymanager' fwiw
local events = {}
exports('registerKey', function(name, description, defaultMapper, defaultIndex, onDown, onUp)
if not events[name] then
events[name] = {}
RegisterCommand('+' .. name, function()
for _, data in ipairs(events[name]) do
if data.down then
data.down()
end
end
end)
RegisterCommand('-' .. name, function()
for _, data in ipairs(events[name]) do
if data.up then
data.up()
end
end
end)
RegisterKeyMapping('+' .. name, description, defaultMapper, defaultIndex)
end
table.insert(events[name], { down = onDown, up = onUp })
end)
-- to remove commands from chat
AddEventHandler('onClientResourceStart', function()
Wait(750)
for name, _ in pairs(events) do
TriggerEvent('chat:removeSuggestion', '/+' .. name)
TriggerEvent('chat:removeSuggestion', '/-' .. name)
end
end)
To use:
local handsUp = false
exports['keymanager'].registerKey('i', 'whatever i want "bound to i"', 'keyboard', 'i', function()
CreateThread(function()
handsUp = true
while handsUp do
Wait(0)
TaskHandsUp(PlayerPedId(), 250, PlayerPedId(), -1, true)
end
end)
end, function()
handsUp = false
end)
Maybe next time be less passive-aggressive in your first post and consider that you’re not the only person on this world, nor that everyone should be like ‘other mp clients’ you named as such.
Also, getting your friends to reply-brigade your issue is really helpful (not).
Thanks, my main problem was that I could not bind functions to it, and I never thinks about it as you did. And also, I had some of my users complaining that key binds do not work for them. I will test this one, and If I encounter an issue, I will post on a bug-report
Howdy,
@d-bubble I believe that’s not a Dev Lead’s attitude fam.
Chill out please, lets talk about this.
Indeed I’m with @Matin_Dark in this.
What he/she really mean is that there’s no use to that REGISTER_KEY_MAPPING because you’d have to put another loop after all, which is not what the community asks for!
This block down here is what we really asking, not some sort of loop
I would ask for your attention to this block of code here:
// 0x71 is the F2 key code
mp.keys.bind(0x71, true, function() {
mp.events.callRemote('keypress:F2'); // Calling server event "keypress:F2"
mp.gui.chat.push('F2 key is pressed.');
});
which is pretty simple, Idk if you’ve ever worked with jquery event handlers or not
simply the code will look like
$('.sombutton').on('keyup',function () {
console.log('button was pressed');
});
In this scenario you don’t have to put your code in a loop which creates hell of a process for every frame, That’d drop people’s fps right ?
So please calm down be like real grown ups so we can solve this issue hm ?
You do not. Read the message I posted above. Also, stop wanting this to be like every other random shit “mp client” just because you don’t understand the provisions given here.
Also, as I said above:
One person posting a complaint or question is enough, no need for 5 other people to state they’re “with them” and whatnot.
Also, stop spamming my forum DMs. Seriously.