From e319aab0c4160dccf14387c452615e0a652b0a67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Krac=C3=ADk?= Date: Mon, 25 May 2020 01:55:31 +0200 Subject: [PATCH] Hid: mouse --- hidinput.py | 31 ++++++++++++++++++++++++++++++- templates/hid.html | 1 - templates/mouse.html | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 templates/mouse.html diff --git a/hidinput.py b/hidinput.py index 00d3272..100c726 100644 --- a/hidinput.py +++ b/hidinput.py @@ -19,10 +19,12 @@ app = Flask(__name__) NULL = chr(0) hiddev = None +hidmouse = None def hid_init(): - global hiddev + global hiddev, hidmouse hiddev=open('/dev/hidg0', 'rb+') + hiddev=open('/dev/hidg1', 'rb+') def hid_write(data): if hiddev is None: @@ -31,6 +33,15 @@ def hid_write(data): hiddev.write(data.encode()) hiddev.flush() +def hid_mouse_write(btn, x, y, wheel): + if hidmouse is None: + return False + + data = chr(btn)+chr(x)+chr(y)+chr(wheel) + + hidmouse.write(data.encode()) + hidmouse.flush() + def send_key(hidkey, shift, alt, ctlr): modkey = ord(NULL) @@ -70,6 +81,24 @@ def get_hid_by_jscode(rawkeycode): def index(): return render_template("hid.html") +@app.route("/mouse.html") +def index(): + return render_template("mouse.html") + + +@app.route("/hid/mouse", methods=["POST"]) +def mouse(): + mouseevent = json.loads(request.data) + + btn = mouseevent['btn'] + x = mouseevent['x'] + y = mouseevent['y'] + wheel = mouseevent['wheel'] + + hid_mouse_write(btn, x, y, wheel) + + return Response("", mimetype = "text/plain") + @app.route("/hid/keyboard", methods=["POST"]) def keypress(): diff --git a/templates/hid.html b/templates/hid.html index eab86a9..a1ab649 100644 --- a/templates/hid.html +++ b/templates/hid.html @@ -9,7 +9,6 @@ HID input service, POST data to /keyboard or /mouse
-
diff --git a/templates/mouse.html b/templates/mouse.html new file mode 100644 index 0000000..8215c96 --- /dev/null +++ b/templates/mouse.html @@ -0,0 +1,40 @@ + + + + + Klávesnice remote SSH + + + + + HID mouse service, POST data to /mouse
+
+
+ +