大家好,我正在写android应用控制电脑光标的功能。我将监听区域Motion_event的数据通过socket传送到电脑来控制光标,但是光标的移动很不顺畅,不知道大家有没有好的方法可以解决这个问题。
android传送的代码:
@Override
public boolean onTouch(View arg0, MotionEvent event) {
// TODO Auto-generated method stub
while(true){
if(event.getPointerCount() == 1){
if(CommonUtils.mLastTouchX == 0
&& CommonUtils.mLastTouchY == 0){
CommonUtils.mLastTouchX = event.getX();
CommonUtils.mLastTouchY = event.getY();
}
int dx = (int)(event.getX() - CommonUtils.mLastTouchX);
int dy = (int)(event.getY() - CommonUtils.mLastTouchY);
Message locationMessage = new Message();
locationMessage.what = 0x333;
locationMessage.obj = dx + "," + dy;
connectThread.sendDataHandler.sendMessage(locationMessage);
CommonUtils.mLastTouchX = event.getX();
CommonUtils.mLastTouchY = event.getY();
}
if(event.getAction() == MotionEvent.ACTION_UP){
CommonUtils.mLastTouchX = 0;
CommonUtils.mLastTouchY = 0;
}
return true;
}
}
C#服务器端接收数据移动的代码:
int dx = Convert.ToInt32(command.Split(',')[0]);
int dy = Convert.ToInt32(command.Split(',')[1]);
Cursor.Position = new Point(Cursor.Position.X + dx, Cursor.Position.Y + dy);
请大家指教,谢谢!