Mouse Hid: working demo

This commit is contained in:
Petr Kracik 2020-05-25 02:35:10 +02:00
parent e319aab0c4
commit bd2540cbc0
2 changed files with 26 additions and 11 deletions

View File

@ -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")

View File

@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="utf-8">
<title>Klávesnice remote SSH</title>
<title>Mouse remote</title>
<style>
</style>
<script src="https://code.jquery.com/jquery-3.5.0.js"></script>
@ -12,15 +12,20 @@
<div>
</div>
<button onclick="sendMouse()" value="Test mouse"/>
<input type="button" onclick="sendMouse(0, 0, -10);" value="^" />
<input type="button" onclick="sendMouse(0, -10, 0);" value="<" />
<input type="button" onclick="sendMouse(0, 10, 0);" value=">" />
<input type="button" onclick="sendMouse(0, 0, 10);" value="v" /><br />
<input type="button" onclick="sendMouse(1, 0, 0);" value="LEFT" />
<input type="button" onclick="sendMouse(2, 0, 0);" value="RIGHT" />
<script>
function sendMouse() {
function sendMouse(btn, x, y) {
var obj = {
x: 0,
y: 0,
btn: 0,
x: x,
y: y,
btn: btn,
wheel: 0,
}