NUI - Detecting when a key is pressed?

Evening all (Well night for me),

I’m pretty darn new to NUI, however it seems to be the only option I have when it comes to producing text boxes a player can actually type in to (considering all we really have are Controls).

Ideally what I’m after is a way to have it detect or register when a letter is typed? I assume it’s doable though this really has confused me.

I’m fairly lost as to have I can have it listen for when the user types, seeing as all I’ve found in regards to tutorials is some form of whitelist thing, then a thread of someone asking about creating a text box only to have the standard text box (black box, centred on screen).

So what is it exactly your asking here?

if you want to get when the user presses a key then use this:

if IsControlJustPressed(1, 38) then -- E
end

else if your looking for the user to enter a string of text then use this:

DisplayOnscreenKeyboard(1, "FMMC_KEY_TIP8", "", "", "", "", "", 25)

hope this helps

Pretty sure HTML forms work… If you want a custom text entry box, just create a HTML form with a text box.

Then when the user clicks a button or hit enter, or whatever, just post it to the nui callback.

Bing bang bosh. You have a custom text entry field.

I’m looking specifically for typing any key, seeing as simply checking if The control key is pressed doesn’t really cut it since not every letter can be checked.

I mean I’ve seen it before, log in to see a simple text box for entering your password. I was simply hoping I could just use NUI to essentially trigger when I hit a key.

If I can’t have it trigger something in a lua file when any key is pressed, then I’ll have to settle for creating a text box, however I’m unsure how I’d send the contents of the text box over to a lua file

so an output for every key?

I have written my own script to get the number of every key when you press it and display it to the user, would this help?

It would mean you can get the number for the key you wish to assign.

I’m pretty sure you can’t do that at the minute. There’s a feature request somewhere for the devs to implement a proper key library.

You may be able to set the focus on a blank HTML page and use the keydown (I think its keydown) event in js to get your desired key.

Edit:
You can use jquery post to send the data back to Lua. Look here:

As long as I could fetch whatever key has been pressed (not just those used as control keys), then that’d be amazing!

here is a client side script, join the server and it should draw a notification above the map to tell you what the key number is you can then use this for is control just pressed or what ever you choose,

https://drive.google.com/file/d/0B7Nc8xRLPRLeeFJhemlPWUJlaFU/view?usp=sharing

i have this as a toggelable option in my menu on my private server, you can choose to do the same for yours if you would like.

Unfortunately it seems that this method doesn’t register any input from

I, J, K, O or U :confused:

Probably because they aren’t bound to anything…

What you’re trying to do (get keys) currently won’t work. I’ve said this before. You can only get when a control is pressed (controls are bound to keys).

And as I’ve said, I’m aware that it’s only keys that are bound to actions. However when an individual comes up to you with a possible solution, I’m obviously going to try it.

Seems my only option will be to look in to NUI and see if I can get a functioning method, granted that feature request couldn’t come quick enough! Ahah.

1 Like

Lol. His code only displayed when a control was pressed. It didn’t provide any “solution”. Plus, if you were aware that you couldn’t get when a key is pressed you should’ve known that unbound keys wouldn’t have worked.

Patronising moderators, there’s something new.

what are the key codes

I believe all the information your looking for has been answered here ^^^^

Controls are what you can get they are bound ingame see

All controls that you can use can be found on the docs Here