Game does not register first key keypress after toggling NUI Focus

After disabling NUI focus the game does not register first keypress with IsControlJustPressed, starts working on second and subsequent keypresses.

In the following repro code, upon pressing ENTER, NUI Focus is toggled, on second press of ENTER nothing happens, on third ENTER press NUI gets toggled again and on fourth ENTER press nothing happens again.

Expected behaviour would be that for every ENTER keypress NUI would toggle.

Citizen.CreateThread(function()
  while true do
    Wait(0)
    
    if IsControlJustPressed(1, 176) then
      print("ENTER PRESSED")
      print('toggling focus')
      SetNuiFocus(true, true)
      Wait(100)
      SetNuiFocus(false, false)
      print("focus toggled")
    end
  end
end)```
1 Like

Hello. You can try to change “IsControlJustPressed” with “IsControlJustReleased”. It’s not totally the same action but it works for me.

Thats a workaround I havent considered - check press and release, if a button is registered released but not pressed, register it as if it was pressed.

Still its just a workaround and fixing it would be better.