Hid: mouse
This commit is contained in:
		
							
								
								
									
										31
									
								
								hidinput.py
									
									
									
									
									
								
							
							
						
						
									
										31
									
								
								hidinput.py
									
									
									
									
									
								
							@@ -19,10 +19,12 @@ app = Flask(__name__)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
NULL = chr(0)
 | 
					NULL = chr(0)
 | 
				
			||||||
hiddev = None
 | 
					hiddev = None
 | 
				
			||||||
 | 
					hidmouse = None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def hid_init():
 | 
					def hid_init():
 | 
				
			||||||
    global hiddev
 | 
					    global hiddev, hidmouse
 | 
				
			||||||
    hiddev=open('/dev/hidg0', 'rb+')
 | 
					    hiddev=open('/dev/hidg0', 'rb+')
 | 
				
			||||||
 | 
					    hiddev=open('/dev/hidg1', 'rb+')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def hid_write(data):
 | 
					def hid_write(data):
 | 
				
			||||||
    if hiddev is None:
 | 
					    if hiddev is None:
 | 
				
			||||||
@@ -31,6 +33,15 @@ def hid_write(data):
 | 
				
			|||||||
    hiddev.write(data.encode())
 | 
					    hiddev.write(data.encode())
 | 
				
			||||||
    hiddev.flush()
 | 
					    hiddev.flush()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def hid_mouse_write(btn, x, y, wheel):
 | 
				
			||||||
 | 
					    if hidmouse is None:
 | 
				
			||||||
 | 
					        return False
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    data = chr(btn)+chr(x)+chr(y)+chr(wheel)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    hidmouse.write(data.encode())
 | 
				
			||||||
 | 
					    hidmouse.flush()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def send_key(hidkey, shift, alt, ctlr):
 | 
					def send_key(hidkey, shift, alt, ctlr):
 | 
				
			||||||
    modkey = ord(NULL)
 | 
					    modkey = ord(NULL)
 | 
				
			||||||
@@ -70,6 +81,24 @@ def get_hid_by_jscode(rawkeycode):
 | 
				
			|||||||
def index():
 | 
					def index():
 | 
				
			||||||
	return render_template("hid.html")
 | 
						return render_template("hid.html")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@app.route("/mouse.html")
 | 
				
			||||||
 | 
					def index():
 | 
				
			||||||
 | 
						return render_template("mouse.html")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@app.route("/hid/mouse", methods=["POST"])
 | 
				
			||||||
 | 
					def mouse():
 | 
				
			||||||
 | 
					    mouseevent = json.loads(request.data)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    btn = mouseevent['btn']
 | 
				
			||||||
 | 
					    x = mouseevent['x']
 | 
				
			||||||
 | 
					    y = mouseevent['y']
 | 
				
			||||||
 | 
					    wheel = mouseevent['wheel']
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    hid_mouse_write(btn, x, y, wheel)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return Response("", mimetype = "text/plain")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@app.route("/hid/keyboard", methods=["POST"])
 | 
					@app.route("/hid/keyboard", methods=["POST"])
 | 
				
			||||||
def keypress():
 | 
					def keypress():
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -9,7 +9,6 @@
 | 
				
			|||||||
</head>
 | 
					</head>
 | 
				
			||||||
<body>
 | 
					<body>
 | 
				
			||||||
	HID input service, POST data to /keyboard or /mouse <br/>
 | 
						HID input service, POST data to /keyboard or /mouse <br/>
 | 
				
			||||||
 | 
					 | 
				
			||||||
<div>
 | 
					<div>
 | 
				
			||||||
</div>
 | 
					</div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										40
									
								
								templates/mouse.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								templates/mouse.html
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,40 @@
 | 
				
			|||||||
 | 
					<!doctype html>
 | 
				
			||||||
 | 
					<html lang="en">
 | 
				
			||||||
 | 
					<head>
 | 
				
			||||||
 | 
					  <meta charset="utf-8">
 | 
				
			||||||
 | 
					  <title>Klávesnice remote SSH</title>
 | 
				
			||||||
 | 
					  <style>
 | 
				
			||||||
 | 
					  </style>
 | 
				
			||||||
 | 
					  <script src="https://code.jquery.com/jquery-3.5.0.js"></script>
 | 
				
			||||||
 | 
					</head>
 | 
				
			||||||
 | 
					<body>
 | 
				
			||||||
 | 
						HID mouse service, POST data to /mouse <br/>
 | 
				
			||||||
 | 
					<div>
 | 
				
			||||||
 | 
					</div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<button onclick="sendMouse()" value="Test mouse"/>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<script>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function sendMouse() {
 | 
				
			||||||
 | 
					  var obj = {
 | 
				
			||||||
 | 
					    x: 0,
 | 
				
			||||||
 | 
					    y: 0,
 | 
				
			||||||
 | 
					    btn: 0,
 | 
				
			||||||
 | 
					    wheel: 0,
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  var ret = $.ajax({
 | 
				
			||||||
 | 
					      type: "POST",
 | 
				
			||||||
 | 
					      url: "hid/mouse",
 | 
				
			||||||
 | 
					      data: JSON.stringify(obj),
 | 
				
			||||||
 | 
					      contentType: "application/json; charset=utf-8",
 | 
				
			||||||
 | 
					      dataType: "json"
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					</script>
 | 
				
			||||||
 | 
					 
 | 
				
			||||||
 | 
					</body>
 | 
				
			||||||
 | 
					</html>
 | 
				
			||||||
		Reference in New Issue
	
	Block a user