Hello there,
I’m currently developing a resource and got a problem with control detection.
In my lua script I detect if a Control (in this case F2) got pressed with IsControlJustPressed() which sends a NUI message over to my JS event listener and executes SetNuiFocus(true, true). When the event is triggered I send back to the lua script another NUI message with some information.
Now the problem. With enabled NUI focus the game will not register the F2-key was released and therefor IsControlJustReleased() always returns false, UNLESS I move my cursor or press my ALT-key.
So when I disable the NUI focus now with a different key (or with F2 aswell, doesn’t matter) I didn’t move my mouse nor pressed the ALT-key so the game still didn’t detect the F2-key was released already.
So when I want to do the same precedure again and press F2 this time no NUI message will be send to my JS since the game still didn’t register the key release and therefor IsControlJustPressed() won’t return true. On the second try though it will work since the first try made the IsControlJustReleased() happen.
Any ideas?
Green
I dont really understand what you are trying to ask, but when the NUI is visible AND focused the IsControl functions dont work as all the keys then get forwarded to the NUI.
Well maybe I didn’t describe it good enough. I know that you can’t check for controls while NUI is focused and thats not what I’m trying to do.
But if you focus the NUI with a IsControlJustPressed() function the game won’t notice you released that key already. So if you close the NUI now again with another key you won’t be able to press that first key again to open the NUI another time. Because the game still expects you to release that key. The next IsControlJustPressed() will just return true on the second keystroke of that mentioned key.
The odd thing here is that if you move your cursor a bit or press the alt key on a focused NUI the game will detect your released key (which you pressed to focus the NUI).
I made a workaround now but just wanted to state this here in case its possible to adjust this weird behaviour. I would absolutely understand if the game can’t detect my releasing keystroke since I used the pressing stroke to focus the NUI, but why the hell it detects it if you move your cursor or press your alt key 
I’m also experiencing this issue.
For example, you detect when a player pressed the middle-mouse button like this;
IsControlJustPressed(0, 27)
You then change NUI focus so you can navigate your HTML menu. Once done, you hide the HTML and disable NUI focus as per usual.
However after doing this, the player will have to press the middle-mouse button once before it will trigger again;
- Player hits middle-mouse button, HTML menu opens along with NUI focus.
- Player hides the HTML menu by releasing the middle-mouse button (done via onmouseup event in JS). Disable NUI focus.
- Player hits middle-mouse button to show menu again - nothing happens.
- Player hits middle-mouse button again - this time it shows.
Same problem, did you found a solution?
Well whenever I want to change my focus to the NUI with a key stroke now I will only use the release event so it can’t get stuck within the events.