Creating a "block-type" menu?

I have that happening here.

Try putting SetNuiFocus( false ) instead of SetNuiFocus( false, false ).

1 Like

I have tried both and get the same result :cry: The print("Cursor should go now...") doesn’t even echo “Cursor should go now…” into the F8 Console. I think there is something wrong with one of the two statement(s)

RegisterNUICallback('closeMenu', function()
	print("Cursor should go now...")
	 SetNuiFocus( false )
end)
$(document).keyup(function(e){
    if (e.keyCode == 27){
        $.post('http://UI/closeMenu');
    }
 })

but not sure what because nothing in the Callback is happening at the moment.

Make sure in your NUI Callback you’re passing data and cb as arguments, and that in the post statement you are sending some data using JSON.stringify({ event: "your_event_name" })

1 Like

OK I updated the statement to:

RegisterNUICallback('closeMenu', function(data, cb)
	 print("Cursor should go now...")
	 SetNuiFocus(false, false)
end)

what exactly do you mean pass data in the $.post statement. Aren’t I doing that already?

$(document).keyup(function(e){
	if (e.keyCode == 27){
		print("Cursor should go now...")
		$(".btn-group").css('display', 'none')
		//$(".btn-group").hide();
		$.post('http://UI/closeMenu');
	}
})

No, you should put

$.post( "http://UI/closeMenu", JSON.stringify( { event: "close" } ) );
1 Like

I tried to run it with that but the cursor is still visible when the menu closes or am I missing something? Do I need to create an event in the client.lua?!

I’ll download your code and see if I can take a look.

1 Like

OK, thank you - I appreciate it!

Sorry… I haven’t looked at your code (from my last reply). I just assumed you were only doing .hide.

This is some code that I use, I’m not sure if it will help you.

UI page:

document.onkeyup = function (data) {
    if (data.which == 27) { // Escape key
        $.post('http://rpp/NUIFocusOff', JSON.stringify({}));
    }
};

Client Lua:

RegisterNUICallback('NUIFocusOff', function()
    SetNuiFocus(false, false)
end)

Unfortunately that doesn’t work and gives me same issue. Really blows that no matter how I set the function up the cursor is still staying on the screen. Hopefully after WolfKnight runs my code and adjusts it a bit it’ll work :worried:

I downloaded it, nothing works. Your menu won’t open, only the cursor shows up, is this what happens for you right now?

Right now my menu opens but when it closes the cursor stays and I can’t use any controls. Here is a video of what happens exactly.

Add another <script> tag underneath the </body> and put the document.keyup thing in there. I had an issue where I had to have it after everything.

</body>

<script type="text/javascript">

document.onkeyup = function (data) {
    if (data.which == 27) { // Escape key
        $.post('http://rpp/NUIFocusOff', JSON.stringify({}));
    }
};

</script>

When doing that the menu will not close when hitting the ESC key.

Wtf… I have no idea. I’ll have to play with this myself when I get home later.

Excuse me from last response, I forgot to put in the $('.btn-group').css('display', 'none') in it. The menu actually does close but the cursor still remains on the screen as usual.

1 Like

Well the cursor remaining and you being able to move it around is the SetNuiFocus, which needs to go back to being false with the RegisterNuiCallback

1 Like

Yes which I have not changed. It still looks like the following:

RegisterNUICallback('closeMenu', function()
	print("Cursor should go now...")
	SetNuiFocus(false, false)
end)

but nothing from the Callback function is actually happening (not even the print("Cursor should go now...")).

This is exactly how I have it setup and it works on mine. Maybe try it with the .click thing too, like I have. Try removing the data, cb from the Registercallback thing and just use ().

</body>

<script type="text/javascript">

$("#subby").click(function(){
    $.post('http://rpp/NUIFocusOff', JSON.stringify({}));
});

document.onkeyup = function (data) {
    if (data.which == 27) { // Escape key
        $.post('http://rpp/NUIFocusOff', JSON.stringify({}));
    }
};

</script>

RegisterNUICallback('NUIFocusOff', function()
    SetNuiFocus(false, false)
end)

1 Like