如何在屏幕上生成虚拟触摸?

How to generate virtual touch on screen?

我想通过在我的应用之外的屏幕上编程来生成触摸事件。我的应用目前有一个浮动 window。我正在尝试制作类似 repetitouch 的东西 我使用了 Hover library to create a floating window to display some message and buttons. I tried following this 答案,但 Hover 库没有为我提供任何要处理的视图 [当我尝试使用 view.dispatchTouchEvent(motionEvent); ] ClassName.this、getView() 等都不起作用。 是否有任何其他浮动 window 库在实现后提供视图,以便我可以通过代码生成触摸。 我可以使用服务来完成这项任务吗?如果是,我应该使用什么?

已更新::::: 参考下面的link显示How to stimulate touch event in android

(希望你觉得有用)

我找到了我的解决方案。我使用了仪器。

InstrumentationObj.sendPointerSync(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_DOWN, x_coordinate, y_coordinate, 0));