问题
In XUL or JavaScript, is there a way to move the mouse cursor to specified position?
回答1:
The only time that Gecko moves the mouse is on Windows for the snap-to-default-button effect. This is used by XUL dialogs and wizards. The backend code doesn't actually check that you're giving it a button; any XUL control works. The mouse is moved to the centre of the element, if that point is on-screen, and the window is active. Normally the code checks that the system cursor snapping is enabled, but there is a preference that overrides that.
回答2:
No. you cannot move a mouse cursor using javascript.
But you can do this.
Hide the cursor. Load an image shaped like cursor. Animate the image.
回答3:
You can use nsIDOMWindowUtils.sendNativeMouseEvent(x, y, 0, 0, null) to reposition the mouse cursor. Perhaps combined with window.screenX/Y to work out where you should move the cursor to, since sendNativeMouseEvent
seems to treat the (x,y)
as absolute screen coordinates.
I haven't tested this method very thoroughly, so there could be caveats. I can't think of any myself.
I know this is an old question, but I have not seen this solution suggested anywhere before, and it's not exactly obvious.
I've only tested with Firefox v48 on Windows 7. Here, sendNativeMouseEvent
calls SetCursorPos to perform the actual repositioning.
来源:https://stackoverflow.com/questions/4960372/in-xul-or-javascript-is-there-a-way-to-move-the-mouse-cursor-to-specified-posit