[HELP] How do I SetNuiFocus back to (false, false) after keypressed/released?

Hi all, I’m working on some ui animation and I need it to slide out on keypress (which is defined in a js function via classlist.Toggle) but in order to do that I have to SetNuiFocus(true,false) in lua.

The only problem with that is when it’s pressed, I can’t walk, open chat or use my keyboard for just about anything besides the keybind to toggle the animation.

How do I set it so SetNuiFocus(true, false) happens when ‘K’ is pressed to toggle on and then immediately as it is released, SetNuiFocus(false, false) happens so I can go back to walking around with the menu open. The menu is purely visual, it requires no interaction, it just needs to show.

make a nui callback on the js side that listens for a keypress

1 Like

How do I do that?

This is currently in my client.lua

Citizen.CreateThread(function()
    while true do
        Citizen.Wait(0)
        
        if IsControlJustPressed(1, 311) then
            SetNuiFocus(true, false)
            SendNUIMessage({
                variable = true,
            })
        end
    end
end)

variable = true activates my keydown event in JS.

window.addEventListener('message', function(event)
    {
        var item = event.data;
    if(item.variable){
      document.addEventListener("keydown", function(e) {
        let key = e.which || e.keyCode;
        if (key == 75 || key == 75) { 

bump!

Did you ever figure out how to do this?