From 33bca6c35c1089230bfa17b8b128159c210cf509 Mon Sep 17 00:00:00 2001 From: Petr Kracik Date: Sun, 24 May 2020 11:08:49 +0200 Subject: [PATCH] Hid: initial commit --- hidinput.py | 67 ++++++++++++++++++++++++++++++++++++++++++++++ templates/hid.html | 5 ++++ 2 files changed, 72 insertions(+) create mode 100644 hidinput.py create mode 100644 templates/hid.html diff --git a/hidinput.py b/hidinput.py new file mode 100644 index 0000000..9b8ccac --- /dev/null +++ b/hidinput.py @@ -0,0 +1,67 @@ +from flask import Response +from flask import Flask +from flask import render_template +import threading +import argparse +import datetime +import time + +lock = threading.Lock() + +# initialize a flask object +app = Flask(__name__) + +NULL = chr(0) +hiddev = None + +def init(): + hiddev=open('/dev/hidg0', 'rb+') + +def hidwrite(data): + if hiddev is None: + return False + + hiddev.write(data.encode()) + hiddev.flush() + + +def send_key(hidkey, shift, alt, ctlr, superkey): + # TODO handle mod keys + hidwrite(NULL*2+chr(hidkey)+NULL*5) + hidwrite(NULL*8) + + +def get_hid_by_scancode(scancode): + + +@app.route("/") +def index(): + return render_template("hid.html") + + +@app.route("/hid/keyboard", methods=["POST"]) +def keypress(): + return Response("Stisknuto ", mimetype = "text/plain") + + +# check to see if this is the main thread of execution +if __name__ == '__main__': + # construct the argument parser and parse command line arguments + ap = argparse.ArgumentParser() + ap.add_argument("-i", "--ip", type=str, required=True, + help="ip address of the device") + ap.add_argument("-o", "--port", type=int, required=True, + help="ephemeral port number of the server (1024 to 65535)") + ap.add_argument("-f", "--frame-count", type=int, default=32, + help="# of frames used to construct the background model") + args = vars(ap.parse_args()) + + 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() + diff --git a/templates/hid.html b/templates/hid.html new file mode 100644 index 0000000..f8c212a --- /dev/null +++ b/templates/hid.html @@ -0,0 +1,5 @@ + + + HID input service, POST data to /keyboard or /mouse + +