以编程方式在 Android 屏幕上移动鼠标指针
我正在开发一个 Android 应用程序,我想在 Android 平板电脑上移动“鼠标”指针/光标。我知道这是可能的,因为当我将鼠标(USB 或 BT)连接到 Android 平板电脑(Honeycomb+)时,会出现一个光标,并且我可以仅使用鼠标与平板电脑交互。我想在平板电脑上通过 Java 控制鼠标。
我已经有第二个设备可以与平板电脑进行通信,并且可以将指针坐标传输到平板电脑。
不,我不能使用蓝牙。我使用的第二台设备有 WiFi,但无法驱动蓝牙。 我的想法是必须有一种方法来移动鼠标指针。
I am developing an Android application where I would like to move the "mouse" pointer/cursor on an Android tablet. I know this is possible because when I connect a mouse (USB or BT) to an Android tablet (Honeycomb+), a cursor appears and I can interact with the tablet using the mouse only. I would like to control that mouse from Java on the Tablet.
I already have a second device that can communicate the tablet and which can stream pointer coordinates to it.
And no I can't use bluetooth. The second device that I'm using has WiFi but no ability to drive BlueTooth.
My thought is that there must be a way to move the mouse pointer.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
可以通过 AccessibilityService API 以编程方式控制 Android 中的鼠标指针。
以下是 Play 商店中的示例应用:EVA Facial Mouse 应用程序
这是一个 github 存储库,用于通过 WiFi 控制鼠标指针(API 级别 21):chetbox/android-mouse-cursor
我已分叉并将后一个存储库更新到 API 级别 27:Ra-Na/android-mouse-cursor
It is possible to control the mouse pointer in Android programmatically via the AccessibilityService API.
Here is an example app in the play store: EVA Facial Mouse app
Here is a github repository for controlling the mouse pointer via WiFi (API level 21): chetbox/android-mouse-cursor
I have forked and updated the latter repo to API level 27: Ra-Na/android-mouse-cursor
除非通过固件或专门的仪器代码,否则这是不可能的。普通的 SDK 应用程序无法通过这种方式注入输入事件。
This is not possible, except via firmware or specialized instrumentation code. Ordinary SDK applications cannot inject input events this way.
我认为我们现在可以通过添加覆盖视图来控制光标移动并捕获光标运动事件,隐藏它们。
绘制自己的指针。将触摸事件传递给底层视图。
在您选择的位置显示指针,然后相对于原始光标移动它
处理捕获的指针事件 - 文档参考
I think we can control the cursor moving now by adding an overlay view and capture the cursor motion events, hide them.
Draw own pointer. Pass the touch events to the underlying view.
Show pointer in the position of your choice and then move it relative to the original cursor
Handle captured pointer events - Documentation reference