feliz navidad
funcionalidades
1 click drecho
2 click izquierdo
3 mover el mouse
4 doble click
4 soporte movil
5 interfase web
les paso el codigo para que puedan controlar el mause desde movil XD
requiere que habras puerto 8000 XD
solo entran desde el movil a la ruta que sale de la consola
Código
package otpserver.simple; import com.sun.net.httpserver.HttpExchange; import com.sun.net.httpserver.HttpHandler; import com.sun.net.httpserver.HttpServer; import java.awt.Robot; import java.io.IOException; import java.io.OutputStream; import java.net.InetSocketAddress; import java.net.URI; import java.nio.charset.StandardCharsets; import java.net.InetAddress; import java.util.Enumeration; import java.net.NetworkInterface; public class MouseControlServer { private static final String HTML_CONTENT = "<!DOCTYPE html><html><head><title>Control Remoto del Mouse</title><meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no'><style>" + "body{font-family:Arial,sans-serif;margin:0;padding:20px;background-color:#f0f0f0;user-select:none;touch-action:none}" + ".container{max-width:400px;margin:0 auto;background:white;padding:20px;border-radius:10px;box-shadow:0 2px 5px rgba(0,0,0,0.2)}" + ".pad{width:300px;height:300px;background:#e0e0e0;margin:20px auto;border-radius:10px;position:relative;touch-action:none}" + ".buttons{display:grid;grid-template-columns:repeat(2,1fr);gap:10px;margin-top:20px}" + "button{padding:15px;border:none;border-radius:5px;background:#007bff;color:white;font-size:16px;cursor:pointer;transition:background 0.3s;touch-action:manipulation}" + "button:active{background:#0056b3}" + ".coordinates{text-align:center;margin-top:10px;font-size:14px;color:#666}" + "</style></head><body><div class='container'>" + "<h2 style='text-align:center'>Control Remoto del Mouse</h2>" + "<div class='pad' id='touchpad'></div>" + "<div class='coordinates' id='coords'>X: 0, Y: 0</div>" + "<div class='buttons'>" + "<button ontouchstart='sendCommand(\"click\")'>Click Izquierdo</button>" + "<button ontouchstart='sendCommand(\"rightclick\")'>Click Derecho</button>" + "<button ontouchstart='sendCommand(\"doubleclick\")'>Doble Click</button>" + "<button ontouchstart='toggleTracking()'>Activar/Desactivar</button>" + "</div></div><script>" + "let isTracking=false;let lastX=0,lastY=0;" + "const touchpad=document.getElementById('touchpad');" + "const coordsDisplay=document.getElementById('coords');" + "let sensitivity=2;" + "function toggleTracking(){isTracking=!isTracking}" + "function updatePosition(e){" + "if(!isTracking)return;" + "e.preventDefault();" + "const touch=e.touches[0];" + "const rect=touchpad.getBoundingClientRect();" + "const x=touch.clientX-rect.left;" + "const y=touch.clientY-rect.top;" + "const deltaX=(x-lastX)*sensitivity;" + "const deltaY=(y-lastY)*sensitivity;" + "if(lastX!==0&&lastY!==0){" + "fetch(`/mouse?action=move&x=${deltaX}&y=${deltaY}`)" + "}" + "lastX=x;lastY=y;" + "coordsDisplay.textContent=`X: ${Math.round(x)}, Y: ${Math.round(y)}`" + "}" + "function sendCommand(action){fetch(`/mouse?action=${action}`)}" + "touchpad.addEventListener('touchstart',(e)=>{isTracking=true;lastX=0;lastY=0;e.preventDefault();});" + "touchpad.addEventListener('touchmove',updatePosition,{passive:false});" + "touchpad.addEventListener('touchend',(e)=>{isTracking=false;e.preventDefault();});" + "</script></body></html>"; HttpServer server = HttpServer.create(new InetSocketAddress("0.0.0.0", 8000), 0); server.createContext("/", new WebHandler()); server.createContext("/mouse", new MouseHandler()); server.setExecutor(null); server.start(); Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces(); while (interfaces.hasMoreElements()) { NetworkInterface ni = interfaces.nextElement(); Enumeration<InetAddress> addresses = ni.getInetAddresses(); while (addresses.hasMoreElements()) { if (!addr.isLoopbackAddress() && addr.isSiteLocalAddress()) { } } } } static class WebHandler implements HttpHandler { @Override exchange.getResponseHeaders().add("Access-Control-Allow-Origin", "*"); exchange.getResponseHeaders().add("Access-Control-Allow-Methods", "GET, POST, OPTIONS"); exchange.getResponseHeaders().add("Access-Control-Allow-Headers", "Content-Type,Authorization"); exchange.getResponseHeaders().set("Content-Type", "text/html; charset=UTF-8"); if (exchange.getRequestMethod().equalsIgnoreCase("OPTIONS")) { exchange.sendResponseHeaders(204, -1); return; } byte[] response = HTML_CONTENT.getBytes(StandardCharsets.UTF_8); exchange.sendResponseHeaders(200, response.length); os.write(response); } } } static class MouseHandler implements HttpHandler { private int lastScreenX = 0; private int lastScreenY = 0; public MouseHandler() { try { lastScreenX = (int) p.getX(); lastScreenY = (int) p.getY(); e.printStackTrace(); } } @Override exchange.getResponseHeaders().add("Access-Control-Allow-Origin", "*"); exchange.getResponseHeaders().add("Access-Control-Allow-Methods", "GET, POST, OPTIONS"); exchange.getResponseHeaders().add("Access-Control-Allow-Headers", "Content-Type,Authorization"); if (exchange.getRequestMethod().equalsIgnoreCase("OPTIONS")) { exchange.sendResponseHeaders(204, -1); return; } try { URI uri = exchange.getRequestURI(); if (query != null) { double x = 0, y = 0; if (keyValue.length == 2) { switch (keyValue[0]) { case "action": action = keyValue[1]; break; } } } switch (action) { case "move": lastScreenX += x; lastScreenY += y; robot.mouseMove(lastScreenX, lastScreenY); break; case "click": robot.mousePress(16); robot.delay(100); robot.mouseRelease(16); break; case "rightclick": robot.mousePress(4); robot.delay(100); robot.mouseRelease(4); break; case "doubleclick": robot.mousePress(16); robot.delay(50); robot.mouseRelease(16); robot.delay(50); robot.mousePress(16); robot.delay(50); robot.mouseRelease(16); break; } } exchange.sendResponseHeaders(200, response.length()); os.write(response.getBytes()); } exchange.sendResponseHeaders(500, response.length()); os.write(response.getBytes()); } } } } }