【问题标题】:Android device as touchpadAndroid 设备作为触摸板
【发布时间】:2014-04-08 22:44:40
【问题描述】:

所以我正面临一个问题,这似乎微不足道,应该很容易解决,但我似乎不知道该怎么做

我的目标是将我的安卓设备用作通过蓝牙连接的触摸板。它有点工作,但它会立即将指针移动到我触摸的点,而不是仅在我在屏幕上移动手指时移动。

        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)来模拟鼠标

【问题讨论】:

    标签: android bluetooth touch mouse


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-08-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多