在XUL或JavaScript中,有没有办法将鼠标光标移动到指定位置?
在XUL或JavaScript中,有没有办法将鼠标光标移动到指定位置?
In XUL or JavaScript, is there a way to move the mouse cursor to specified position?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Gecko 唯一一次移动鼠标是在 Windows 上,以实现捕捉到默认按钮的效果。这是由 XUL 对话框 使用的巫师。后端代码实际上并不检查您是否给了它一个按钮;而是检查您是否给了它一个按钮。任何 XUL 控件 都可以工作。如果该点位于屏幕上并且窗口处于活动状态,则鼠标将移动到元素的中心。通常,代码会检查系统光标捕捉是否已启用,但有一个首选项会覆盖它。
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.
不可以。您无法使用 javascript 移动鼠标光标。
但你可以做到这一点。
隐藏光标。加载形状像光标的图像。使图像动画化。
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.
您可以使用
nsIDOMWindowUtils .sendNativeMouseEvent(x, y, 0, 0, null)
重新定位鼠标光标。也许与window.screenX/Y
来确定应将光标移动到的位置,因为
sendNativeMouseEvent
似乎将(x,y)
视为绝对屏幕坐标。我还没有非常彻底地测试过这个方法,所以可能有一些警告。我自己也想不出来。
我知道这是一个老问题,但我之前没有在任何地方看到过这个解决方案,而且它并不明显。
我只在 Windows 7 上使用 Firefox v48 进行了测试。这里,
sendNativeMouseEvent
调用SetCursorPos
执行实际的重新定位。You can use
nsIDOMWindowUtils.sendNativeMouseEvent(x, y, 0, 0, null)
to reposition the mouse cursor. Perhaps combined withwindow.screenX/Y
to work out where you should move the cursor to, sincesendNativeMouseEvent
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
callsSetCursorPos
to perform the actual repositioning.