【问题标题】:How to Send Mouse Movements and Clicks from Android to Desktop如何将鼠标移动和点击从 Android 发送到桌面
【发布时间】:2015-06-30 05:52:39
【问题描述】:

我想制作一个可以通过蓝牙控制桌面鼠标光标的应用(Android Studio 和 Java)。

我该怎么做呢?是否有任何功能可以控制通过 BT 连接的设备的光标?提前致谢!

【问题讨论】:

  • 尝试表达您的问题,使其符合 SO 准则。目前存在的这个问题过于宽泛/主要基于意见。

标签: java android bluetooth mouse-cursor


【解决方案1】:

这是一个迟到的答案,但一种解决方案是设计如下架构:

  • 能够使用MotionEvent.ACTION_MOVE 读取触摸输入并记录先前和当前值并计算差异的应用程序,通过蓝牙 UDP 客户端将其发送到服务器。

    @Override
    public boolean onTouch(MotionEvent e)
    {
    
       switch(e)
       {     
            case MotionEvent.ACTION_DOWN:
                float initX = e.getX();        
                float initY = e.getY();
                return true;
    
            case MotionEvent.ACTION_MOVE:        
                float curX = initX - e.getX();
                float curY = initY - e.getY();
                sendThroughUDP(curX, curY);
                return true; 
        }
    }
    
  • 在您的桌面上运行的服务器能够读取此内容。例如一个简单的通过蓝牙的 java UDP 服务器,这可能是给定的here。这将接收这些值,然后将这些值注入到 Robot 类(如果是 Java)。

 //implement the UDP over the bluetooth stack.
 public static void main(String [] args)
 {
      UDPOverBluetoothServer UDPBT = new UDPOverBluetoothSever(socketInformation);
      int xValue = UDPBT.getX();          
      int yValue = UDPBT.getY();
      Robot robot = new Robot();
      Point mousePointer = MouseInfo.getPointerInfo().getLocation();
      robot.mouseMove(mousePointer.x - xValue, mousePointer.y - yValue); 
 }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-02-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-12
    • 1970-01-01
    相关资源
    最近更新 更多