HID Mouse: absolute mouse support
This commit is contained in:
parent
f22f2eeb67
commit
06519e7009
35
hidinput.py
35
hidinput.py
@ -17,12 +17,14 @@ app = Flask(__name__)
|
|||||||
|
|
||||||
hiddev = None
|
hiddev = None
|
||||||
hidmouse = None
|
hidmouse = None
|
||||||
|
hidmouseabs = None
|
||||||
|
|
||||||
|
|
||||||
def hid_init():
|
def hid_init():
|
||||||
global hiddev, hidmouse
|
global hiddev, hidmouse, hidmouseabs
|
||||||
hiddev = open('/dev/hidg0', 'rb+')
|
hiddev = open('/dev/hidg0', 'rb+')
|
||||||
hidmouse = open('/dev/hidg1', 'rb+')
|
hidmouse = open('/dev/hidg1', 'rb+')
|
||||||
|
hidmouseabs = open('/dev/hidg2', 'rb+')
|
||||||
|
|
||||||
|
|
||||||
def hid_write(data):
|
def hid_write(data):
|
||||||
@ -47,6 +49,20 @@ def hid_mouse_write(btn, x, y, wheel):
|
|||||||
hidmouse.flush()
|
hidmouse.flush()
|
||||||
|
|
||||||
|
|
||||||
|
def hid_mouse_writeabs(btn, x, y, wheel):
|
||||||
|
if hidmouseabs is None:
|
||||||
|
return False
|
||||||
|
|
||||||
|
data = bytearray(6)
|
||||||
|
data[0] = btn
|
||||||
|
data[1:3] = x.to_bytes(2, byteorder='little')
|
||||||
|
data[3:5] = y.to_bytes(2, byteorder='little')
|
||||||
|
data[5] = wheel
|
||||||
|
|
||||||
|
hidmouseabs.write(data)
|
||||||
|
hidmouseabs.flush()
|
||||||
|
|
||||||
|
|
||||||
def send_key(hidkey, shift, alt, ctlr, mod):
|
def send_key(hidkey, shift, alt, ctlr, mod):
|
||||||
data = bytearray(8)
|
data = bytearray(8)
|
||||||
if shift:
|
if shift:
|
||||||
@ -91,7 +107,6 @@ def index():
|
|||||||
def mouseindex():
|
def mouseindex():
|
||||||
return render_template("mouse.html")
|
return render_template("mouse.html")
|
||||||
|
|
||||||
|
|
||||||
@app.route("/hid/mouse", methods=["POST"])
|
@app.route("/hid/mouse", methods=["POST"])
|
||||||
def mouse():
|
def mouse():
|
||||||
mouseevent = json.loads(request.data)
|
mouseevent = json.loads(request.data)
|
||||||
@ -111,6 +126,22 @@ def mouse():
|
|||||||
|
|
||||||
return Response("", mimetype="text/plain")
|
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")
|
||||||
|
|
||||||
|
|
||||||
@app.route("/hid/keyboard", methods=["POST"])
|
@app.route("/hid/keyboard", methods=["POST"])
|
||||||
def keypress():
|
def keypress():
|
||||||
|
@ -18,9 +18,37 @@
|
|||||||
<input type="button" onclick="sendMouse(0, 0, 10);" value="v" /><br />
|
<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(1, 0, 0);" value="LEFT" />
|
||||||
<input type="button" onclick="sendMouse(2, 0, 0);" value="RIGHT" />
|
<input type="button" onclick="sendMouse(2, 0, 0);" value="RIGHT" />
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
|
var btn=0;
|
||||||
|
var posX=0;
|
||||||
|
var posY=0;
|
||||||
|
|
||||||
|
$(document).ready(function(){
|
||||||
|
|
||||||
|
$("canvas").mousedown(function(event){
|
||||||
|
btn=event.buttons;
|
||||||
|
handleMouse();
|
||||||
|
});
|
||||||
|
$("canvas").mouseup(function(event){
|
||||||
|
btn=event.buttons;
|
||||||
|
handleMouse();
|
||||||
|
});
|
||||||
|
|
||||||
|
$("canvas").mousemove(function(event){
|
||||||
|
// sendMouse(0, event.originalEvent.movementX, event.originalEvent.movementY);
|
||||||
|
posX=event.offsetX;
|
||||||
|
posY=event.offsetY;
|
||||||
|
handleMouse();
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
function handleMouse() {
|
||||||
|
$("span").text(btn +", "+ posX + ", " + posY);
|
||||||
|
sendMouse(btn, posX, posY);
|
||||||
|
}
|
||||||
|
|
||||||
function sendMouse(btn, x, y) {
|
function sendMouse(btn, x, y) {
|
||||||
var obj = {
|
var obj = {
|
||||||
x: x,
|
x: x,
|
||||||
@ -31,7 +59,7 @@ function sendMouse(btn, x, y) {
|
|||||||
|
|
||||||
var ret = $.ajax({
|
var ret = $.ajax({
|
||||||
type: "POST",
|
type: "POST",
|
||||||
url: "hid/mouse",
|
url: "hid/mouseabs",
|
||||||
data: JSON.stringify(obj),
|
data: JSON.stringify(obj),
|
||||||
contentType: "application/json; charset=utf-8",
|
contentType: "application/json; charset=utf-8",
|
||||||
dataType: "json"
|
dataType: "json"
|
||||||
@ -40,6 +68,8 @@ function sendMouse(btn, x, y) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
<span></span><br/><br/>
|
||||||
|
<canvas width=500 height=500 style="border: 1px solid black" oncontextmenu="return false"></canvas>
|
||||||
|
<!--<img src="placeholder.png" width=1920 height=1080 onmousemove='console.log("aaa");' />-->
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
Loading…
Reference in New Issue
Block a user