Read mouse position outside scene

Hello! There is any way to read mouse position inside and outside the scene screen every frame. I’ve tried to search on web, but found nothing. pls help. i know about scene.pointerX(Y) but it works only inside scene.

Well I am not sure if I understood properly. But mostly everything that is outside the scene is not directly Babylon but javascript. So you can just use something like this.

Babylon.js Playground (31-34)

You can see in console the values of the scene.pointerX which shows values only inside the scene. But clientX shows values over whole window (including scene tho).

i know about this, but need values outside window too, ive searchin and found way like a pointercapture but only when mousedown, any way to make like this on every rendered frame instead mousedown?

Hi @coldestheart. Welcome :smiley:
Something like this maybe
https://www.babylonjs-playground.com/#8JTMDX
Cheers!

1 Like

@coldestheart Welcome to the forum!
I hope this kinda is what you want:
https://www.babylonjs-playground.com/#F7ZZJF#9

Notice that scene coordinates are different from the outside!
If I understand it correctly, then the scene coords represent the canvas ones…
There are some ways to calculate them globally, but would need to investigate on my own :sweat_smile:

1 Like

Its good, thanks but in my situation i need change camera alpha without mouse clicking, but with mouse tracking include when mouse outside browser window, can anyone help me plz.

I’ve try to use this but it works only when object hovering(

You will need to do further research but this might be helpful Pointer Lock API - Web APIs | MDN

Thank, I will try to read more.

this is not the case, cause mouse cursor need to be free all the time, to use ui elements