From fb2c4b487419267b1af2314a451fdedfc293d821 Mon Sep 17 00:00:00 2001 From: Petr Kracik Date: Fri, 5 Jun 2020 16:32:24 +0200 Subject: [PATCH] HID Input: socketIO test --- hid_descriptors.txt | 3 +++ hidinput.py | 27 ++++++++++++++++++--------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/hid_descriptors.txt b/hid_descriptors.txt index 84aa13b..27ad822 100644 --- a/hid_descriptors.txt +++ b/hid_descriptors.txt @@ -34,6 +34,9 @@ a1 01 // Collection Application c0 // End collection +00010101 +00100101 + input bytes (4 bytes) 0 - 0 data / 1 constant 1 - 0 array / 1 variable diff --git a/hidinput.py b/hidinput.py index 16046f1..51d60e5 100644 --- a/hidinput.py +++ b/hidinput.py @@ -2,6 +2,7 @@ from flask import Response from flask import Flask from flask import render_template from flask import request +from flask_socketio import SocketIO import threading import argparse import json @@ -14,11 +15,13 @@ lock = threading.Lock() # initialize a flask object app = Flask(__name__) +socketio = SocketIO(app) hiddev = None hidmouse = None hidmouseabs = None +hid_init() def hid_init(): global hiddev, hidmouse, hidmouseabs @@ -130,7 +133,6 @@ def mouse(): def mouseabs(): mouseevent = json.loads(request.data) print(mouseevent) - btn = mouseevent['btn'] x = mouseevent['x'] y = mouseevent['y'] @@ -143,6 +145,20 @@ def mouseabs(): return Response("", mimetype="text/plain") +@socketio.on('mouseEvent') +def handle_my_custom_event(json): + mouseevent = json.loads(json) + 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) + + @app.route("/hid/keyboard", methods=["POST"]) def keypress(): keyevent = json.loads(request.data) @@ -177,12 +193,5 @@ if __name__ == '__main__': help="# of frames used to construct the background model") args = vars(ap.parse_args()) - hid_init() - app.run(host=args["ip"], port=args["port"], debug=True, - threaded=True, use_reloader=False) - - # Clean up - if hiddev is not None: - print("Closing hid") - hiddev.close() + use_reloader=False)