From 06519e700926d5a68980a70a6c016f391ae1ef31 Mon Sep 17 00:00:00 2001 From: Petr Kracik Date: Fri, 5 Jun 2020 15:04:27 +0200 Subject: [PATCH] HID Mouse: absolute mouse support --- hidinput.py | 35 +++++++++++++++++++++++++++++++++-- templates/mouse.html | 36 +++++++++++++++++++++++++++++++++--- 2 files changed, 66 insertions(+), 5 deletions(-) diff --git a/hidinput.py b/hidinput.py index d3aab59..16046f1 100644 --- a/hidinput.py +++ b/hidinput.py @@ -17,12 +17,14 @@ app = Flask(__name__) hiddev = None hidmouse = None +hidmouseabs = None def hid_init(): - global hiddev, hidmouse + global hiddev, hidmouse, hidmouseabs hiddev = open('/dev/hidg0', 'rb+') hidmouse = open('/dev/hidg1', 'rb+') + hidmouseabs = open('/dev/hidg2', 'rb+') def hid_write(data): @@ -47,6 +49,20 @@ def hid_mouse_write(btn, x, y, wheel): hidmouse.flush() +def hid_mouse_writeabs(btn, x, y, wheel): + if hidmouseabs is None: + return False + + data = bytearray(6) + data[0] = btn + data[1:3] = x.to_bytes(2, byteorder='little') + data[3:5] = y.to_bytes(2, byteorder='little') + data[5] = wheel + + hidmouseabs.write(data) + hidmouseabs.flush() + + def send_key(hidkey, shift, alt, ctlr, mod): data = bytearray(8) if shift: @@ -91,7 +107,6 @@ def index(): def mouseindex(): return render_template("mouse.html") - @app.route("/hid/mouse", methods=["POST"]) def mouse(): mouseevent = json.loads(request.data) @@ -111,6 +126,22 @@ def mouse(): return Response("", mimetype="text/plain") +@app.route("/hid/mouseabs", methods=["POST"]) +def mouseabs(): + mouseevent = json.loads(request.data) + print(mouseevent) + + btn = mouseevent['btn'] + x = mouseevent['x'] + y = mouseevent['y'] + wheel = mouseevent['wheel'] + + print("X: {}, Y: {}".format(x, y)) + + hid_mouse_writeabs(btn, x, y, wheel) + + return Response("", mimetype="text/plain") + @app.route("/hid/keyboard", methods=["POST"]) def keypress(): diff --git a/templates/mouse.html b/templates/mouse.html index e3b91d4..4e0bec2 100644 --- a/templates/mouse.html +++ b/templates/mouse.html @@ -18,9 +18,37 @@
- - +

+ +