黄炜-HH 2015-06-15 06:54 采纳率: 0%
浏览 1621

Android控制电脑鼠标不顺畅

   大家好,我正在写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);

        请大家指教,谢谢!
  • 写回答

3条回答

  • Android_Ky 2015-06-15 08:26
    关注

    首先要确定耗时在哪儿

    我觉得是socket。

    你看看socket代码有没有优化点。

    有些卡顿很正常。

    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?