作为触摸板的Android设备

作为触摸板的Android设备,android,bluetooth,touch,mouse,Android,Bluetooth,Touch,Mouse,所以我面对一个问题,它看起来很琐碎,应该很容易解决,但我似乎不知道如何解决它 我的目标是将我的android设备用作通过蓝牙连接的触摸板。它在某种程度上起作用,但它会立即将指针移动到我触摸的点,而不是仅当我在屏幕上移动手指时才移动 touchpad.setOnTouchListener(new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent event) {

所以我面对一个问题,它看起来很琐碎,应该很容易解决,但我似乎不知道如何解决它

我的目标是将我的android设备用作通过蓝牙连接的触摸板。它在某种程度上起作用,但它会立即将指针移动到我触摸的点,而不是仅当我在屏幕上移动手指时才移动

        touchpad.setOnTouchListener(new View.OnTouchListener() {
        public boolean onTouch(View v, MotionEvent event) {
            if(event.getAction()==MotionEvent.ACTION_DOWN){

            }

            if(event.getAction() == MotionEvent.ACTION_MOVE)
            {
                String xps = "X: "+(event.getX());
                String yps = "Y: "+(event.getY());


                cmd  = xps + " " + yps + "\n";                  
                moveCursor(cmd);

            }

            return true;
        }
    });

private void moveCursor(String command)
{

        byte[] cmd = command.getBytes();
        try 
        {
            OPS.write(cmd);
        }
        catch (IOException e){

            Log.e("Command error", command + " could not be executed");
        }
        catch(NullPointerException e)
        {
            e.printStackTrace();
        }
    }
}

在服务器端,我只是通过调用Robot.MouseMove(x,y)

来使用Robot模拟鼠标。我不是Java开发人员,以前也没有使用过Robot,因此我无法为您提供可用的代码示例……但我已经使用鼠标事件和触摸事件编写了一些可拖动的代码。我认为您缺少的是一个起点,然后将增量(更改)添加到起点。在我看来,通过您的代码示例,您可以从MotionEvent.ACTION\u中获取起点(并将其存储在变量中),现在您的值为空,然后在MotionEvent.ACTION\u移动部分的顶部获取增量。从这里开始,您将使用起点,并在移动事件中添加增量