|
| 1 | +import logging |
| 2 | +import sys |
| 3 | +import threading |
| 4 | + |
| 5 | +import pyautogui as p |
| 6 | +from flask import Flask, request |
| 7 | + |
| 8 | +log = logging.getLogger("werkzeug") |
| 9 | +log.setLevel(logging.ERROR) |
| 10 | + |
| 11 | +cli = sys.modules["flask.cli"] |
| 12 | +cli.show_server_banner = lambda *x: None |
| 13 | + |
| 14 | +app = Flask("app") |
| 15 | + |
| 16 | +p.FAILSAFE = False |
| 17 | +moving = False |
| 18 | +drag = False |
| 19 | +type_data = "" |
| 20 | +old_data = "" |
| 21 | +coords = (0, 0) |
| 22 | +lastcords = (0, 0) |
| 23 | +lstmcord = (0, 0) |
| 24 | +lstlen = 0 |
| 25 | +coords = [(0, 0)] |
| 26 | + |
| 27 | + |
| 28 | +@app.route("/", methods=["GET", "POST"]) |
| 29 | +def send() -> str: |
| 30 | + # print("here") |
| 31 | + if request.method == "POST": |
| 32 | + # print(request.get_json()) |
| 33 | + return "ok" |
| 34 | + return """<!DOCTYPE html> |
| 35 | +<html> |
| 36 | + <head> |
| 37 | + <meta http-equiv="content-type" content="text/html; charset=utf-8"/> |
| 38 | + <meta name='viewport' |
| 39 | + content='width=device-width, initial-scale=1.0, maximum-scale=1.0, |
| 40 | + user-scalable=0' > |
| 41 | + <script type="text/javascript" charset="utf-8"> |
| 42 | + function init() { |
| 43 | + var touchzone = document.getElementById("zone"); |
| 44 | + touchzone.addEventListener("touchend", clicke, false); |
| 45 | + touchzone.addEventListener("touchmove", handle, false); |
| 46 | + touchzone.addEventListener("touchstart", tostart, false); |
| 47 | + var scrollzone = document.getElementById("scroll"); |
| 48 | + scrollzone.addEventListener("touchmove", scrollmove, false); |
| 49 | + scrollzone.addEventListener("touchstart", tostart, false); |
| 50 | + } |
| 51 | +
|
| 52 | +function scrollmove(event){ |
| 53 | + var a = event.touches[0].pageX; |
| 54 | + var b = event.touches[0].pageY; |
| 55 | + var xhttp = new XMLHttpRequest(); |
| 56 | + xhttp.onreadystatechange = function() { |
| 57 | + }; |
| 58 | + xhttp.open("POST", "scroller", true); |
| 59 | + xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); |
| 60 | + xhttp.send("a="+a+"&b="+b); |
| 61 | +} |
| 62 | +
|
| 63 | +
|
| 64 | +function tostart(event){ |
| 65 | + var a = event.touches[0].pageX; |
| 66 | + var b = event.touches[0].pageY; |
| 67 | + var xhttp = new XMLHttpRequest(); |
| 68 | + xhttp.onreadystatechange = function() { |
| 69 | + }; |
| 70 | + xhttp.open("POST", "tstart", true); |
| 71 | + xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); |
| 72 | + xhttp.send("a="+a+"&b="+b); |
| 73 | +} |
| 74 | +
|
| 75 | +function clicke(event) { |
| 76 | + var xhttp = new XMLHttpRequest(); |
| 77 | + xhttp.onreadystatechange = function() { |
| 78 | + }; |
| 79 | + var a = event.changedTouches[0].pageY; |
| 80 | + xhttp.open("POST", "click", true); |
| 81 | + xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); |
| 82 | + xhttp.send("a="+a); |
| 83 | +} |
| 84 | +
|
| 85 | +function dragm() { |
| 86 | + var btn = document.getElementById("drag"); |
| 87 | + var xhttp = new XMLHttpRequest(); |
| 88 | + xhttp.onreadystatechange = function() { |
| 89 | + }; |
| 90 | + xhttp.open("POST", "dradhandler", true); |
| 91 | + xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); |
| 92 | + xhttp.send(); |
| 93 | +
|
| 94 | + if (btn.innerHTML == "Drag mouse"){ |
| 95 | + btn.innerHTML = "Move mouse"; |
| 96 | + } |
| 97 | + else{ |
| 98 | + btn.innerHTML = "Drag mouse"; |
| 99 | + } |
| 100 | +} |
| 101 | +
|
| 102 | +function sendData(a,b,g) { |
| 103 | + var xhttp = new XMLHttpRequest(); |
| 104 | + xhttp.onreadystatechange = function() { |
| 105 | + }; |
| 106 | + xhttp.open("POST", "handler", true); |
| 107 | + xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); |
| 108 | + xhttp.send("a="+a+"&b="+b); |
| 109 | +} |
| 110 | +
|
| 111 | +
|
| 112 | + function handle(event) { |
| 113 | + var alpha = event.touches[0].pageX; |
| 114 | + var beta = event.touches[0].pageY; |
| 115 | + sendData(alpha,beta); |
| 116 | +} |
| 117 | +
|
| 118 | +
|
| 119 | +function on_input(){ |
| 120 | + var data = document.getElementById("inpfield").value; |
| 121 | + var xhttp = new XMLHttpRequest(); |
| 122 | + xhttp.onreadystatechange = function() { |
| 123 | + }; |
| 124 | + xhttp.open("POST", "typed", true); |
| 125 | + xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); |
| 126 | + xhttp.send("data="+data); |
| 127 | +} |
| 128 | +function enter_but(){ |
| 129 | + var xhttp = new XMLHttpRequest(); |
| 130 | + xhttp.onreadystatechange = function() { |
| 131 | + }; |
| 132 | + xhttp.open("POST", "enter", true); |
| 133 | + xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); |
| 134 | + xhttp.send("data="+"data"); |
| 135 | +} |
| 136 | +
|
| 137 | +
|
| 138 | +
|
| 139 | +
|
| 140 | + </script> |
| 141 | +
|
| 142 | + <meta name="" content=""> |
| 143 | + <title></title> |
| 144 | + <style> |
| 145 | + .center{ |
| 146 | + position: fixed; |
| 147 | + background-color: rgb(230,230,230); |
| 148 | + width:80%; |
| 149 | + height:400px; |
| 150 | + top:300px; |
| 151 | + left:46%; |
| 152 | + color:rgb(200,200,200); |
| 153 | + font-weight:bold; |
| 154 | + transform: translate(-50%,-50%); |
| 155 | + -webkit-touch-callout: none; |
| 156 | + -webkit-user-select: none; |
| 157 | + -khtml-user-select: none; |
| 158 | + -moz-user-select: none; |
| 159 | + -ms-user-select: none; |
| 160 | + user-select: none; |
| 161 | + } |
| 162 | + html{ |
| 163 | + touch-action:pan-down |
| 164 | + } |
| 165 | +
|
| 166 | + .scrollarea{ |
| 167 | + position: fixed; |
| 168 | + background-color: rgb(230,230,230); |
| 169 | + width:30px; |
| 170 | + height:400px; |
| 171 | + top:300px; |
| 172 | + left:92.05%; |
| 173 | + color:rgb(200,200,200); |
| 174 | + font-weight:bold; |
| 175 | + transform: translate(-50%,-50%); |
| 176 | + -webkit-touch-callout: none; |
| 177 | + -webkit-user-select: none; |
| 178 | + -khtml-user-select: none; |
| 179 | + -moz-user-select: none; |
| 180 | + -ms-user-select: none; |
| 181 | + user-select: none; |
| 182 | + text-align:center; |
| 183 | + } |
| 184 | +
|
| 185 | +
|
| 186 | + </style> |
| 187 | + </head> |
| 188 | + <body onload="init()"> |
| 189 | + <p style="text-align:center;">Type on PC |
| 190 | + <input id="inpfield"type="text" oninput=on_input()></input> |
| 191 | + <button type="button" onclick="enter_but()">Enter</button></p> |
| 192 | + <div style="text-align:center;"> |
| 193 | + <button id="drag" type="button" onclick="dragm()">Drag mouse</button> |
| 194 | + </div> |
| 195 | + <div class="center" id="zone"> |
| 196 | + <p align="center"><br><br><br><br><br><br>Left click area<br><br><br><br><br><br><hr></p> |
| 197 | + <p align="center"><br>Right click area</p> |
| 198 | + </div> |
| 199 | + <div class="scrollarea" id="scroll"> |
| 200 | + <p><br><br><br><br><br>S<br>C<br>R<br>O<br>L<br>L</p> |
| 201 | + </div> |
| 202 | + </body> |
| 203 | +</html>""" |
| 204 | + |
| 205 | + |
| 206 | +@app.route("/handler", methods=["POST"]) |
| 207 | +def handle() -> str: |
| 208 | + global moving, cordlst, lastcords |
| 209 | + lst = [] |
| 210 | + a = request.form["a"] |
| 211 | + b = request.form["b"] |
| 212 | + a = float(a) |
| 213 | + b = float(b) |
| 214 | + moving = True |
| 215 | + coords = (a, b) |
| 216 | + lx, ly = lastcords |
| 217 | + cx, cy = coords |
| 218 | + # print(cx,cy) |
| 219 | + # p.moveRel((cx-lx)/2,(cy-ly)/2) |
| 220 | + threading.Thread(target=lambda: p.moveRel((cx - lx) * 2, (cy - ly) * 2)).start() |
| 221 | + lastcords = coords |
| 222 | + return "1" |
| 223 | + |
| 224 | + |
| 225 | +@app.route("/scroller", methods=["POST"]) |
| 226 | +def scrollerr() -> str: |
| 227 | + global moving, cordlst, lastcords2 |
| 228 | + a = request.form["a"] |
| 229 | + b = request.form["b"] |
| 230 | + a = float(a) |
| 231 | + b = float(b) |
| 232 | + coords = (a, b) |
| 233 | + lx, ly = lastcords2 |
| 234 | + cx, cy = coords |
| 235 | + if cy < ly: |
| 236 | + threading.Thread(target=lambda: p.scroll(50)).start() |
| 237 | + if cy > ly: |
| 238 | + threading.Thread(target=lambda: p.scroll(-50)).start() |
| 239 | + lastcords2 = coords |
| 240 | + return "1" |
| 241 | + |
| 242 | + |
| 243 | +@app.route("/tstart", methods=["POST"]) |
| 244 | +def startt() -> str: |
| 245 | + global lastcords, lastcords2 |
| 246 | + # print("end") |
| 247 | + a = request.form["a"] |
| 248 | + b = request.form["b"] |
| 249 | + # print(a,b) |
| 250 | + a = float(a) |
| 251 | + b = float(b) |
| 252 | + lastcords = (a, b) |
| 253 | + lastcords2 = (a, b) |
| 254 | + return "1" |
| 255 | + |
| 256 | + |
| 257 | +@app.route("/click", methods=["POST"]) |
| 258 | +def do_click() -> str: |
| 259 | + global moving |
| 260 | + if not moving: |
| 261 | + a = request.form["a"] |
| 262 | + # print(a) |
| 263 | + a = float(a) |
| 264 | + if a < 400: |
| 265 | + p.click() |
| 266 | + if a >= 400: |
| 267 | + p.rightClick() |
| 268 | + |
| 269 | + moving = False |
| 270 | + return "1" |
| 271 | + |
| 272 | + |
| 273 | +@app.route("/typed", methods=["POST"]) |
| 274 | +def typeit() -> str: |
| 275 | + global type_data, old_data |
| 276 | + data = request.form["data"] |
| 277 | + type_data = str(data) |
| 278 | + if len(type_data) > len(old_data): |
| 279 | + p.typewrite(type_data[len(type_data) - 1]) |
| 280 | + else: |
| 281 | + p.press("backspace", len(old_data) - len(type_data)) |
| 282 | + old_data = type_data |
| 283 | + return "1" |
| 284 | + |
| 285 | + |
| 286 | +@app.route("/enter", methods=["POST"]) |
| 287 | +def slashN() -> str: |
| 288 | + p.press("enter") |
| 289 | + return "1" |
| 290 | + |
| 291 | + |
| 292 | +@app.route("/dradhandler", methods=["POST"]) |
| 293 | +def ghasit_mouse() -> str: |
| 294 | + global drag |
| 295 | + # print(drag) |
| 296 | + if drag == True: |
| 297 | + drag = False |
| 298 | + p.mouseUp() |
| 299 | + |
| 300 | + else: |
| 301 | + drag = True |
| 302 | + p.mouseDown() |
| 303 | + |
| 304 | + return "1" |
| 305 | + |
| 306 | + |
| 307 | +def start_server(port=8000, print_msg=True): |
| 308 | + if print_msg: |
| 309 | + print("Server started at local_ip_of_this_pc:%s" % port) |
| 310 | + print("Print Ctrl+C to exit") |
| 311 | + app.run(host="0.0.0.0", port=port) |
| 312 | + |
| 313 | + |
| 314 | +# app.run(host='0.0.0.0') |
| 315 | +# |
| 316 | +# |
| 317 | +# def main(): |
| 318 | +# app.run(host="192.168.43.17", port=33) |
| 319 | +# |
| 320 | +# |
| 321 | +# if __name__ == "__main__": |
| 322 | +# main() |
| 323 | +# app.run(host='localhost') |
0 commit comments