在输入几个输入后,鼠标停止运行

时间:2018-04-08 15:53:50

标签: java android sockets

客户代码

new Thread()
        {

            public void run()
            {

                mousePad.setOnTouchListener(new View.OnTouchListener() {
                    @Override
                    public boolean onTouch(View v, MotionEvent event) {
                        if(isConnected && out!=null){
                            switch(event.getAction()){
                                case MotionEvent.ACTION_DOWN:
                                    //save X and Y positions when user touches the TextView
                                    initX =event.getX();
                                    initY =event.getY();
                                    mouseMoved=false;
                                    break;
                                case MotionEvent.ACTION_MOVE:
                                    disX = event.getX()- initX; //Mouse movement in x direction
                                    disY = event.getY()- initY; //Mouse movement in y direction
                            /*set init to new position so that continuous mouse movement
                            is captured*/
                                    initX = event.getX();
                                    initY = event.getY();
                                    if(disX !=0|| disY !=0){
                                        try
                                        {

                                            bw = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
                                            bw.write(disX +","+ disY); // to write contents to output stream
                                            l.makeConnection(v);
                                            bw.newLine();
                                            bw.flush();

                                        }
                                        catch (IOException e)
                                        {
                                            Log.i(DebuggString,e.getMessage());
                                        }
                                        out.println(disX +","+ disY); //send mouse movement to server
                                    }
                                    mouseMoved=true;
                                    break;

                            }
                        }
                        return true;
                    }
                });
            }
        }.start();

这是服务器代码

else if(data.contains(","))
                                                {
                                                       float movex=Float.parseFloat(data.split(",")[0]);//extract movement in x direction
                                                        float movey=Float.parseFloat(data.split(",")[1]);//extract movement in y direction
                                                        Point point = MouseInfo.getPointerInfo().getLocation(); //Get current mouse position
                                                        float nowx=point.x;
                                                        float nowy=point.y;

                                                        robot.mouseMove((int)(nowx+movex),(int)(nowy+movey));//Move mouse pointer to new location
                                                        movex = 0;
                                                        movey = 0;
                                                        nowx = 0;
                                                        nowy = 0;

                                                }

没有错误没有logcat或任何出现但服务器卡住而且不接受任何进一步命令的错误。请帮助我完成我的最后一年项目。

它有一吨吨的坐标..当我试着用循环时,原始点被阻挡,光标根本不会从那个位置移动..不知道该怎么办

0 个答案:

没有答案