Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the mouse position without events (without moving the mouse)?

Is it possible to get the mouse position with JavaScript after page loads without any mouse movement event (without moving the mouse)?

like image 251
Norbert Tamas Avatar asked Apr 08 '10 15:04

Norbert Tamas


People also ask

How do I get the mouse position in Python?

To determine the mouse's current position, we use the statement, pyautogui. position(). This function returns a tuple of the position of the mouse's cursor. The first value is the x-coordinate of where the mouse cursor is.

What method do you use to get the mouse point position for a mouse event?

getPointerInfo(). getLocation() might be helpful. It returns a Point object corresponding to current mouse position. getPointerInfo().

How do I find my mouse pointer coordinates?

The clientX property returns the horizontal coordinate (according to the client area) of the mouse pointer when a mouse event was triggered. The client area is the current window. Tip: To get the vertical coordinate (according to the client area) of the mouse pointer, use the clientY property.


1 Answers

Real answer: No, it's not possible.

OK, I have just thought of a way. Overlay your page with a div that covers the whole document. Inside that, create (say) 2,000 x 2,000 <a> elements (so that the :hover pseudo-class will work in IE 6, see), each 1 pixel in size. Create a CSS :hover rule for those <a> elements that changes a property (let's say font-family). In your load handler, cycle through each of the 4 million <a> elements, checking currentStyle / getComputedStyle() until you find the one with the hover font. Extrapolate back from this element to get the co-ordinates within the document.

N.B. DON'T DO THIS.

like image 118
Tim Down Avatar answered Oct 18 '22 03:10

Tim Down