【问题标题】:Simulating joystick movement using AccessibilityService使用 AccessibilityService 模拟操纵杆移动
【发布时间】:2019-12-03 08:50:59
【问题描述】:

我正在尝试使用 AccessibilityService 在屏幕上模拟点击和操纵杆移动。

此外,我还从游戏手柄控制器设备获取输入。做水龙头就可以了。我的问题是模拟屏幕上的操纵杆移动。

由于此功能需要持续时间,我不知道如何使用 GestureDescription 进行连续触摸。

我已使用此代码进行点击:

  public void virtual_touch(int posX, int posY)
{
    Path path = new Path();

    path.moveTo(posX, posY);
    GestureDescription.Builder gestureBuilder = new GestureDescription.Builder();
    gestureBuilder.addStroke(new GestureDescription.StrokeDescription(path, 10, 10));
    //gestureBuilder.build();

    boolean isDispatched = dispatchGesture(gestureBuilder.build(), new AccessibilityService.GestureResultCallback()
    {
        @Override
        public void onCompleted(GestureDescription gestureDescription)
        {
            super.onCompleted(gestureDescription);
            MyUtils.Log("onCompleted");
        }

        @Override
        public void onCancelled(GestureDescription gestureDescription)
        {
            super.onCancelled(gestureDescription);
            MyUtils.Log("onCancelled");
        }
    }, null);

    MyUtils.Log("virtual_touch isDispatched : " + isDispatched);
}

【问题讨论】:

    标签: java android touch joystick


    【解决方案1】:

    对于继续中风使用此方法可能会对您有所帮助。

    将继续 -- 继续描边

    public GestureDescription.StrokeDescription continueStroke(路径路径, 开始时间长, 持续时间长, boolean willContinue)

    boolean:如果此笔划将在下一个手势中继续一个,则为 true,否则为 false。手势完成后,连续的笔划会使指针向下。

    【讨论】:

    • 感谢您的回复。但 willContinue 支持 api 28 及更高版本。
    • 通常这些代码用于 API -26,但请使用 api 28 尝试一次
    • 但我想支持 android 6 及更高版本。 willContinue 适用于 android 8 及更高版本!
    猜你喜欢
    • 2011-07-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多