简体   繁体   English

在XUL或JavaScript中,是否可以将鼠标光标移动到指定位置?

[英]In XUL or JavaScript, is there a way to move the mouse cursor to specified position?

在XUL或JavaScript中,是否可以将鼠标光标移动到指定位置?

You can use nsIDOMWindowUtils.sendNativeMouseEvent(x, y, 0, 0, null) to reposition the mouse cursor. 您可以使用nsIDOMWindowUtils.sendNativeMouseEvent(x, y, 0, 0, null)来重新定位鼠标光标。 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. 也许与window.screenX/Y结合使用, sendNativeMouseEvent光标应移至的位置,因为sendNativeMouseEvent似乎将(x,y)视为绝对屏幕坐标。

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. 我仅在Windows 7上使用Firefox v48进行了测试。在这里, sendNativeMouseEvent调用SetCursorPos来执行实际的重新定位。

No. you cannot move a mouse cursor using javascript. 不可以。您无法使用javascript移动鼠标光标。
But you can do this. 但是你可以做到这一点。
Hide the cursor. 隐藏光标。 Load an image shaped like cursor. 加载形状像光标的图像。 Animate the image. 动画图像。

The only time that Gecko moves the mouse is on Windows for the snap-to-default-button effect. Gecko唯一移动鼠标的时间是在Windows上,以实现默认按钮效果。 This is used by XUL dialogs and wizards. XUL 对话框和向导使用它。 The backend code doesn't actually check that you're giving it a button; 后端代码实际上并不会检查您是否给它提供了一个按钮。 any XUL control works. 任何XUL 控件都能正常工作。 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. 通常,代码会检查是否启用了系统光标捕捉,但是有一个优先选项可以覆盖它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM