diff --git a/android/code/index.js b/android/code/index.js index ddb9c87..c85d3c3 100644 --- a/android/code/index.js +++ b/android/code/index.js @@ -16,7 +16,7 @@ async function spawnPromise(program, args) { //maybe check output of child processe and send errors in some way server.on("connection", (socket) => { socket.on("data", async (dataBuf) => { - data = dataBuf.toString(); + data = dataBuf.toString(); if (data === "screenshot") { socket.write("start"); await spawnPromise("bash", ["/conf/screenshot.sh"]); @@ -29,7 +29,16 @@ server.on("connection", (socket) => { dataSplit[1], dataSplit[2], ]); - } + } else if (data === "back") { + await spawnPromise("bash", [ + "/conf/back.sh", + ]); + } else if (data === "home") { + await spawnPromise("bash", [ + "/conf/home.sh", + ]); + } + }); socket.on("close", (_) => { socket.end(); diff --git a/android/conf/back.sh b/android/conf/back.sh new file mode 100644 index 0000000..8bf7271 --- /dev/null +++ b/android/conf/back.sh @@ -0,0 +1 @@ +/opt/android-sdk-linux/platform-tools/adb shell input keyevent 4 \ No newline at end of file diff --git a/android/conf/home.sh b/android/conf/home.sh new file mode 100644 index 0000000..7fab581 --- /dev/null +++ b/android/conf/home.sh @@ -0,0 +1 @@ +/opt/android-sdk-linux/platform-tools/adb shell input keyevent 3 \ No newline at end of file diff --git a/http_server/code/index.html b/http_server/code/index.html index 584300d..12d17b2 100644 --- a/http_server/code/index.html +++ b/http_server/code/index.html @@ -20,11 +20,36 @@ .screen{ display: inline-block } + + .screen-buttons{ + display: flex; + justify-content: space-around; + margin-top: 5px; + gap: 10px; + } + + .screen-buttons button{ + font-size: 1.1rem; + padding: 10px 20px; + width: 100%; + cursor: pointer; + background-color: transparent; + } + + .screen-buttons button:hover{ + background-color: aqua; + }
- +
+ android screen +
+ + +
+

var screen = document.getElementById("screen"); var clicksLog = document.getElementById("clicks-log"); + const homeButton = document.querySelector(".screen-buttons-home"); + const backButton = document.querySelector(".screen-buttons-back"); + let lastTouch = new Date().getTime(); const calculateElapsedTime = (last) => { @@ -56,6 +84,24 @@ clicksLog.appendChild(clickInfo); } + const registerClick = ({path, logText}) =>{ + const clicksLog = document.getElementById("clicks-log"); + const span = document.createElement("span"); + + waitToLog(logText); + + fetch(path, { + method: "POST", + headers: { + "Content-Type": "application/x-www-form-urlencoded", + }, + }); + } + + homeButton.addEventListener("click", () => registerClick({path: "home", logText: "await homeButton();"})); + + backButton.addEventListener("click", () => registerClick({path: "back", logText: "await backButton();"})); + async function displayImage() { try { const response = await fetch("screen"); @@ -67,25 +113,18 @@ } async function handleTouchEvent(event) { - var phoneX = event.offsetX; - var phoneY = event.offsetY; - if ( - phoneX <= 320 && - phoneX >= 0 && - phoneY <= 640 && - phoneY >= 0 - ) { - waitToLog(`await click(${phoneX}, ${phoneY});`); + const phoneX = event.offsetX; + const phoneY = event.offsetY; - await fetch("touch", { - method: "POST", - headers: { - "Content-Type": "application/x-www-form-urlencoded", - }, - body: `x=${phoneX}&y=${phoneY}`, - }); - - } + waitToLog(`await click(${phoneX}, ${phoneY});`); + + await fetch("touch", { + method: "POST", + headers: { + "Content-Type": "application/x-www-form-urlencoded", + }, + body: `x=${phoneX}&y=${phoneY}`, + }); } async function sleep(time) { diff --git a/http_server/code/index.mjs b/http_server/code/index.mjs index b215049..7b9062f 100644 --- a/http_server/code/index.mjs +++ b/http_server/code/index.mjs @@ -111,4 +111,14 @@ app.get("/", async function (req, res) { res.send(fileData); }); +app.post("/back", function (req, res) { + socket_client.write(`back`); + res.sendStatus(200); +}); + +app.post("/home", function (req, res) { + socket_client.write(`home`); + res.sendStatus(200); +}); + app.listen(8080, () => console.log("Listening in port 8080"));