I would like to get current mouse position but I don't want to use:
$(document).bind('mousemove',function(e){ $("#log").text("e.pageX: " + e.pageX + ", e.pageY: " + e.pageY); });
because I just need to get the position and process the information
To get the current mouse position we are going to trigger a mouse event. In this case we will use 'mousemove' to log the current X and Y coordinates of the mouse to the console.
To set or get the position of the mouse cursor use the static methods QCursor::pos() and QCursor::setPos().
I don't believe there's a way to query the mouse position, but you can use a mousemove
handler that just stores the information away, so you can query the stored information.
jQuery(function($) { var currentMousePos = { x: -1, y: -1 }; $(document).mousemove(function(event) { currentMousePos.x = event.pageX; currentMousePos.y = event.pageY; }); // ELSEWHERE, your code that needs to know the mouse position without an event if (currentMousePos.x < 10) { // .... } });
But almost all code, other than setTimeout
code and such, runs in response to an event, and most events provide the mouse position. So your code that needs to know where the mouse is probably already has access to that information...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With