所以我坐在一个有问题的地方,它似乎微不足道,应该很容易解决,但我似乎无法弄明白该怎么做
我的目标是使用我的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通过调用robot.MouseMove(x,y)模拟鼠标
答案 0 :(得分:0)
我不是Java开发人员,也没有使用过Robot,因此我无法为您提供可用的代码示例......但我已经使用鼠标事件和触摸事件编写了一些可拖动的代码。我相信你缺少的是一个起点,然后将delta(更改)添加到起点。在我的代码示例中,您可以从现在已经为空的MotionEvent.ACTION_DOWN中获取起点(并将其存储在变量中),然后在MotionEvent.ACTION_MOVE部分的顶部获取增量。从那里你将使用你的起点,并在你的移动事件中添加增量。