gpt4 book ai didi

java - 使用motionevents模拟鼠标点击

转载 作者:行者123 更新时间:2023-11-30 06:53:20 27 4
gpt4 key购买 nike

我试图在按下应用程序中的鼠标垫但未移动时模拟鼠标单击。

  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){
out.println(disX +","+ disY); //send mouse movement to server
}
mouseMoved=true;
break;
case MotionEvent.ACTION_UP:
//consider a tap only if usr did not move mouse after ACTION_DOWN
if(!mouseMoved){
out.println(Constants.MOUSE_LEFT_CLICK);
}
}
}
return true;
}
});
}

我已经尝试过这个,但我不明白为什么它不起作用。每次我点击鼠标垫时,鼠标都会移动。我该如何解决这个问题?

最佳答案

尝试使用 if-else 并将按下放在第一位,然后将移动放在 else-case 中。

关于java - 使用motionevents模拟鼠标点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42307934/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com