HID Input: removed relative mouse, removed POST mouse
This commit is contained in:
parent
dcea5e5dca
commit
30e6b30893
59
hidinput.py
59
hidinput.py
@ -18,15 +18,13 @@ app = Flask(__name__)
|
|||||||
socketio = SocketIO(app)
|
socketio = SocketIO(app)
|
||||||
|
|
||||||
hiddev = None
|
hiddev = None
|
||||||
hidmouse = None
|
|
||||||
hidmouseabs = None
|
hidmouseabs = None
|
||||||
|
|
||||||
|
|
||||||
def hid_init():
|
def hid_init():
|
||||||
global hiddev, hidmouse, hidmouseabs
|
global hiddev, hidmouseabs
|
||||||
hiddev = open('/dev/hidg0', 'rb+')
|
hiddev = open('/dev/hidg0', 'rb+')
|
||||||
hidmouse = open('/dev/hidg1', 'rb+')
|
hidmouseabs = open('/dev/hidg1', 'rb+')
|
||||||
hidmouseabs = open('/dev/hidg2', 'rb+')
|
|
||||||
|
|
||||||
|
|
||||||
def hid_write(data):
|
def hid_write(data):
|
||||||
@ -37,20 +35,6 @@ def hid_write(data):
|
|||||||
hiddev.flush()
|
hiddev.flush()
|
||||||
|
|
||||||
|
|
||||||
def hid_mouse_write(btn, x, y, wheel):
|
|
||||||
if hidmouse is None:
|
|
||||||
return False
|
|
||||||
|
|
||||||
data = bytearray(4)
|
|
||||||
data[0] = btn
|
|
||||||
data[1] = x
|
|
||||||
data[2] = y
|
|
||||||
data[3] = wheel
|
|
||||||
|
|
||||||
hidmouse.write(data)
|
|
||||||
hidmouse.flush()
|
|
||||||
|
|
||||||
|
|
||||||
def hid_mouse_writeabs(btn, x, y, wheel):
|
def hid_mouse_writeabs(btn, x, y, wheel):
|
||||||
if hidmouseabs is None:
|
if hidmouseabs is None:
|
||||||
return False
|
return False
|
||||||
@ -101,6 +85,7 @@ def get_hid_by_jscode(rawkeycode):
|
|||||||
|
|
||||||
return hidkeycode, (hidkeyname is not None and "MOD" in hidkeyname)
|
return hidkeycode, (hidkeyname is not None and "MOD" in hidkeyname)
|
||||||
|
|
||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
def index():
|
def index():
|
||||||
return render_template("hid.html")
|
return render_template("hid.html")
|
||||||
@ -109,39 +94,9 @@ def index():
|
|||||||
def mouseindex():
|
def mouseindex():
|
||||||
return render_template("mouse.html")
|
return render_template("mouse.html")
|
||||||
|
|
||||||
@app.route("/hid/mouse", methods=["POST"])
|
@app.route("/keyboard.html")
|
||||||
def mouse():
|
def keyboardIndex():
|
||||||
mouseevent = json.loads(request.data)
|
return render_template("keyboard.html")
|
||||||
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")
|
|
||||||
|
|
||||||
@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")
|
|
||||||
|
|
||||||
|
|
||||||
@socketio.on('mouseEvent')
|
@socketio.on('mouseEvent')
|
||||||
@ -158,6 +113,7 @@ def handle_my_custom_event(data):
|
|||||||
|
|
||||||
hid_mouse_writeabs(btn, x, y, wheel)
|
hid_mouse_writeabs(btn, x, y, wheel)
|
||||||
|
|
||||||
|
|
||||||
@app.route("/hid/keyboard", methods=["POST"])
|
@app.route("/hid/keyboard", methods=["POST"])
|
||||||
def keypress():
|
def keypress():
|
||||||
keyevent = json.loads(request.data)
|
keyevent = json.loads(request.data)
|
||||||
@ -179,6 +135,7 @@ def keypress():
|
|||||||
|
|
||||||
return Response("Press {}".format(hidkeycode), mimetype="text/plain")
|
return Response("Press {}".format(hidkeycode), mimetype="text/plain")
|
||||||
|
|
||||||
|
|
||||||
hid_init()
|
hid_init()
|
||||||
|
|
||||||
# check to see if this is the main thread of execution
|
# check to see if this is the main thread of execution
|
||||||
|
Loading…
Reference in New Issue
Block a user