Set mouse position in software

僤鯓⒐⒋嵵緔 提交于 2019-12-12 07:52:35

问题


I am using an Android Stick (http://www.geekbuying.com/item/Uhost-2-Dual-Core-TV-Box-Mini-PC-Android-4-0-4-RK3066-Cortex-A9-1-6GHZ-1GB-RAM-4G-ROM-with-Bluetooth-WIFI-Skype-XBMC---Black-312467.html) for building an application. The application uses an attached USB webcam for some of it's functionality. Additionally, I connect a mouse to this device which the user can use to navigate through various pages in the application. A left/right movement of the mouse results in navigation to previous/next page.

While the mouse works with the Android device, I additionally require to reset the position of the mouse to the center after every single interaction with the user. Is it possible to set the mouse position using software in Android? I am using View.OnGenericMotionListener to capture the mouse movement.

Currently, I also require to perform a primary mouse button click to bring the mouse in focus inside the application. I want to remove this requirement by either generating the primary mouse button click in software, or otherwise bring the application in software by some other means.

I have been unable to find any APIs to get the above to work. Any help on these would be greatly useful.

Just in case I need to write some sort of drivers to get this thing working, any help in this direction would also be useful.

Any workarounds around this problem, while still using the mouse, could also prove useful.


回答1:


Mouse event is managed by the system framework. You cannot control it on Java side.

On the adb shell you can open /dev/input/uevent device to write mouse events include

  1. relative movement
  2. click action
  3. absolute position (you might want this)

However, you cannot do it as a normal application, unless you do it on a rooted device, or you can use adb shell to start a daemon service in the background to perform the event writing for your application.



来源:https://stackoverflow.com/questions/20502876/set-mouse-position-in-software

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!