diff --git a/hidinput.py b/hidinput.py index 100c726..549e90f 100644 --- a/hidinput.py +++ b/hidinput.py @@ -24,7 +24,7 @@ hidmouse = None def hid_init(): global hiddev, hidmouse hiddev=open('/dev/hidg0', 'rb+') - hiddev=open('/dev/hidg1', 'rb+') + hidmouse=open('/dev/hidg1', 'rb+') def hid_write(data): if hiddev is None: @@ -37,9 +37,13 @@ def hid_mouse_write(btn, x, y, wheel): if hidmouse is None: return False - data = chr(btn)+chr(x)+chr(y)+chr(wheel) + data = bytearray(4) + data[0] = btn + data[1] = x + data[2] = y + data[3] = wheel - hidmouse.write(data.encode()) + hidmouse.write(data) hidmouse.flush() @@ -82,19 +86,25 @@ def index(): return render_template("hid.html") @app.route("/mouse.html") -def index(): +def mouseindex(): return render_template("mouse.html") @app.route("/hid/mouse", methods=["POST"]) def mouse(): mouseevent = json.loads(request.data) + print(mouseevent) btn = mouseevent['btn'] x = mouseevent['x'] y = mouseevent['y'] wheel = mouseevent['wheel'] + x = x if x >= 0 else 255-abs(x) + y = y if y >= 0 else 255-abs(y) + + print ("X: {}, Y: {}".format(x,y)) + hid_mouse_write(btn, x, y, wheel) return Response("", mimetype = "text/plain") diff --git a/templates/mouse.html b/templates/mouse.html index 8215c96..e3b91d4 100644 --- a/templates/mouse.html +++ b/templates/mouse.html @@ -2,7 +2,7 @@ - Klávesnice remote SSH + Mouse remote @@ -12,15 +12,20 @@
-