darkterbears
darkterbears

Reputation: 169

How to Send Mouse Movements and Clicks from Android to Desktop

I want to make an app (Android Studio and Java) that can control a desktop mouse cursor via Bluetooth.

How would I go about doing this? Are there any functions to control the cursor of a device connected via BT? Thanks in advance!

Upvotes: 1

Views: 2375

Answers (1)

HawkPriest
HawkPriest

Reputation: 272

It is a late answer but one solution would be designing the architecture like:

  • An application that is capable of reading the touch input using the MotionEvent.ACTION_MOVE and recording the previous and current values and computing the difference sending it through a bluetooth UDP client to a server.

    @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; 
        }
    }
    
  • A Server running on your desktop capable of reading this. For example a simple java UDP server over bluetooth which is possible as given here. This will receive these values and then inject these values to the Robot class if 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); 
 }

Upvotes: 1

Related Questions