Compare commits

...

26 Commits

Author SHA1 Message Date
844f76e2c2 HID: Mouse raw send to HID device 2020-06-07 15:09:19 +02:00
43b82fd669 HID: Mouse disable json send 2020-06-07 15:08:35 +02:00
0dbf3f9b7a HID: mouse RAW data 2020-06-07 15:07:12 +02:00
42ec2611e3 HID: mouse RAW data 2020-06-07 14:54:55 +02:00
beaad49558 HID: change POST to socketio 2020-06-07 14:29:55 +02:00
44d01c0127 HID: fix zapis 2020-06-07 14:28:27 +02:00
cf5ee01a9c HID: fix ret 2020-06-07 14:27:28 +02:00
0416f32744 HID: removed keystroke for kvm 2020-06-07 14:25:04 +02:00
009d008b5b HID: change POST to socketio 2020-06-07 14:24:15 +02:00
19086199c0 HID Input: KVM page (merge image with hid) 2020-06-07 13:38:06 +02:00
50ab6c43fc HID Input: listen on IPv6 2020-06-07 13:37:45 +02:00
33bc12cb8a Gadget: mass storage name 2020-06-07 13:37:30 +02:00
2a22d0b2bf Docs 2020-06-05 18:15:26 +02:00
ad8a962be8 Gadget: keyboard descriptor to variable 2020-06-05 18:12:44 +02:00
6aaa2f5b0d Gadget: FIX mouse HID for windows 2020-06-05 17:57:19 +02:00
11119bb1cb HID Templates: first merge kbd and mouse 2020-06-05 17:28:34 +02:00
1fa5e4be16 HID Input: cleanup 2020-06-05 17:17:58 +02:00
30e6b30893 HID Input: removed relative mouse, removed POST mouse 2020-06-05 17:17:17 +02:00
dcea5e5dca Gadget: removed relative mouse 2020-06-05 17:16:52 +02:00
bbbf8cbbf6 HID mouse: wheel 2020-06-05 17:06:08 +02:00
6c1bd1235d Mouse template 2020-06-05 17:05:48 +02:00
478cb9c202 HID: run HID service 2020-06-05 16:43:14 +02:00
deb2139d96 HID: mouse over socketio 2020-06-05 16:42:23 +02:00
12644f1e39 HID Input: socketIO mouse 2020-06-05 16:37:44 +02:00
fb2c4b4874 HID Input: socketIO test 2020-06-05 16:32:24 +02:00
ce4842d93e SocketIO: test 2020-06-05 16:14:56 +02:00
12 changed files with 399 additions and 188 deletions

View File

@ -9,7 +9,6 @@ echo "" > UDC
echo "Clean up configs"
rm configs/c.1/hid.kbd0
rm configs/c.1/hid.mouse0
rm configs/c.1/hid.mouse1
rm configs/c.1/mass_storage.disk1
rm configs/c.1/mass_storage.cdrom1
@ -19,7 +18,6 @@ rmdir configs/c.1
echo "Clean up functions"
rmdir functions/hid.kbd0
rmdir functions/hid.mouse0
rmdir functions/hid.mouse1
rmdir functions/mass_storage.disk1
rmdir functions/mass_storage.cdrom1

View File

@ -5,7 +5,19 @@ gserial=$(awk '/Serial/ { print $3 }' /proc/cpuinfo)
gmanufacturer="Petrkr.NET"
gproduct="rPi KVM"
#Mouse 0 relative descriptor
KEYBOARD=""
KEYBOARD="$KEYBOARD\\x05\\x01\\x09\\x06" # Usage generic desktop, Usage keyboard
KEYBOARD="$KEYBOARD\\xa1\\x01\\x05\\x07" # Collection App, Use page Keyboard
KEYBOARD="$KEYBOARD\\x19\\xe0\\x29\\xe7\\x15\\x00\\x25\\x01\\x75\\x01\\x95\\x08" # Usage min (LeftControl) max (Right GUI), log min 0 log min 1, report size 1 count 8
KEYBOARD="$KEYBOARD\\x81\\x02" # Input data, variable, absolute
KEYBOARD="$KEYBOARD\\x75\\x08\\x95\\x01" # Report size 8, count 1
KEYBOARD="$KEYBOARD\\x81\\x03" # Input Const, variable, absolute
KEYBOARD="$KEYBOARD\\x75\\x01\\x95\\x05" # Report size 1 count 5
KEYBOARD="$KEYBOARD\\x05\\x08\\x19\\x01\\x29\\x05\\x91\\x02\\x95\\x01\\x75\\x03\\x91\\x03\\x95\\x06\\x75\\x08\\x15\\x00\\x25\\xff\\x05\\x07\\x19\\x00\\x29\\x65"
KEYBOARD="$KEYBOARD\\x81\\x00" # Input data array absolute
KEYBOARD="$KEYBOARD\\xc0" # End Collection Application
#Mouse absolute descriptor
MOUSE0=""
MOUSE0="$MOUSE0\\x05\\x01\\x09\\x02" # Usage generic desktop, Usage mouse
MOUSE0="$MOUSE0\\xa1\\x01\\x09\\x01" # Collection App, Usage Pointer
@ -14,31 +26,17 @@ MOUSE0="$MOUSE0\\x05\\x09" # Use Page buttons
MOUSE0="$MOUSE0\\x19\\x01\\x29\\x08\\x15\\x00\\x25\\x01\\x75\\x01\\x95\\x08" # Usage min 1, max 8, logical min 0, max 1, report 8, size 1
MOUSE0="$MOUSE0\\x81\\x02" # Input data, variable, absolute
MOUSE0="$MOUSE0\\x05\\x01" # Usage page generic desktop
MOUSE0="$MOUSE0\\x09\\x30\\x09\\x31\\x09\\x38\\x15\\x81\\x25\\x7f\\x75\\x08\\x95\\x03" # Usage X,Y,Wheel, Log min -127, log max 127, size 8, report 3
MOUSE0="$MOUSE0\\x09\\x30\\x35\\x00\\x46\\x80\\x07\\x15\\x00\\x26\\x80\\x07\\x75\\x10\\x95\\x01" # Usage X, Log min 0, log max 1920, size 16, report 1
MOUSE0="$MOUSE0\\x81\\x02" # Input data, variable, absolute
MOUSE0="$MOUSE0\\x05\\x01" # Usage page generic desktop
MOUSE0="$MOUSE0\\x09\\x31\\x35\\x00\\x46\\x38\\x04\\x15\\x00\\x26\\x38\\x04\\x75\\x10\\x95\\x01" # Usage Y, Log min 0, log max 1080, size 16, report 1
MOUSE0="$MOUSE0\\x81\\x02" # Input data, variable, absolute
MOUSE0="$MOUSE0\\x05\\x01" # Usage page generic desktop
MOUSE0="$MOUSE0\\x09\\x38\\x35\\x00\\x45\\x00\\x15\\x81\\x25\\x7f\\x75\\x08\\x95\\x01" # Usage Wheel, log min -127, max 127, size 8, report 1
MOUSE0="$MOUSE0\\x81\\x06" # Input data, variable, relative
MOUSE0="$MOUSE0\\xc0" # End collection Physical
MOUSE0="$MOUSE0\\xc0" # End collection Application
#Mouse 1 absolute descriptor
MOUSE1=""
MOUSE1="$MOUSE1\\x05\\x01\\x09\\x02" # Usage generic desktop, Usage mouse
MOUSE1="$MOUSE1\\xa1\\x01\\x09\\x01" # Collection App, Usage Pointer
MOUSE1="$MOUSE1\\xa1\\x00" # Collection Physical
MOUSE1="$MOUSE1\\x05\\x09" # Use Page buttons
MOUSE1="$MOUSE1\\x19\\x01\\x29\\x08\\x15\\x00\\x25\\x01\\x75\\x01\\x95\\x08" # Usage min 1, max 8, logical min 0, max 1, report 8, size 1
MOUSE1="$MOUSE1\\x81\\x02" # Input data, variable, absolute
MOUSE1="$MOUSE1\\x05\\x01" # Usage page generic desktop
MOUSE1="$MOUSE1\\x09\\x30\\x16\\x00\\x00\\x26\\x80\\x07\\x75\\x10\\x95\\x01" # Usage X, Log min 0, log max 1920, size 16, report 1
MOUSE1="$MOUSE1\\x81\\x02" # Input data, variable, absolute
MOUSE1="$MOUSE1\\x05\\x01" # Usage page generic desktop
MOUSE1="$MOUSE1\\x09\\x31\\x16\\x00\\x00\\x26\\x38\\x04\\x75\\x10\\x95\\x01" # Usage Y, Log min 0, log max 1080, size 16, report 1
MOUSE1="$MOUSE1\\x81\\x02" # Input data, variable, absolute
MOUSE1="$MOUSE1\\x05\\x01" # Usage page generic desktop
MOUSE1="$MOUSE1\\x09\\x38\\x15\\x81\\x25\\x7f\\x75\\x08\\x95\\x01" # Usage Wheel, log min -127, max 127, size 8, report 1
MOUSE1="$MOUSE1\\x81\\x06" # Input data, variable, relative
MOUSE1="$MOUSE1\\xc0" # End collection Physical
MOUSE1="$MOUSE1\\xc0" # End collection Application
cd /sys/kernel/config/usb_gadget/
mkdir -p $gname
cd $gname
@ -66,36 +64,30 @@ mkdir -p functions/hid.kbd0
echo 1 > functions/hid.kbd0/protocol
echo 1 > functions/hid.kbd0/subclass
echo 8 > functions/hid.kbd0/report_length
echo -ne \\x05\\x01\\x09\\x06\\xa1\\x01\\x05\\x07\\x19\\xe0\\x29\\xe7\\x15\\x00\\x25\\x01\\x75\\x01\\x95\\x08\\x81\\x02\\x95\\x01\\x75\\x08\\x81\\x03\\x95\\x05\\x75\\x01\\x05\\x08\\x19\\x01\\x29\\x05\\x91\\x02\\x95\\x01\\x75\\x03\\x91\\x03\\x95\\x06\\x75\\x08\\x15\\x00\\x25\\xff\\x05\\x07\\x19\\x00\\x29\\x65\\x81\\x00\\xc0 > functions/hid.kbd0/report_desc
echo -ne $KEYBOARD > functions/hid.kbd0/report_desc
echo " HID Mouse Relative"
echo " HID Mouse"
mkdir -p functions/hid.mouse0
echo 2 > functions/hid.mouse0/protocol
echo 1 > functions/hid.mouse0/subclass
echo 8 > functions/hid.mouse0/report_length
echo -ne $MOUSE0 > functions/hid.mouse0/report_desc
echo " HID Mouse Absolute"
mkdir -p functions/hid.mouse1
echo 2 > functions/hid.mouse1/protocol
echo 1 > functions/hid.mouse1/subclass
echo 8 > functions/hid.mouse1/report_length
echo -ne $MOUSE1 > functions/hid.mouse1/report_desc
echo " Mass storage"
mkdir -p functions/mass_storage.disk1
echo "RPi KVM DISK" > functions/mass_storage.disk1/lun.0/inquiry_string
echo " CD-ROM"
mkdir -p functions/mass_storage.cdrom1
echo 1 > functions/mass_storage.cdrom1/lun.0/cdrom
echo 1 > functions/mass_storage.cdrom1/lun.0/removable
echo "RPi KVM CDROM" > functions/mass_storage.cdrom1/lun.0/inquiry_string
echo "Activating gadgeds"
ln -s functions/hid.kbd0 configs/c.1/
ln -s functions/hid.mouse0 configs/c.1/
ln -s functions/hid.mouse1 configs/c.1/
ln -s functions/mass_storage.disk1 configs/c.1/
ln -s functions/mass_storage.cdrom1 configs/c.1/
@ -106,4 +98,3 @@ ls /sys/class/udc > UDC
echo "Change permissions"
chgrp input /dev/hidg0; chmod 660 /dev/hidg0
chgrp input /dev/hidg1; chmod 660 /dev/hidg1
chgrp input /dev/hidg2; chmod 660 /dev/hidg2

View File

@ -1,3 +1,5 @@
https://github.com/arduino/Arduino/blob/da9641410a4b8fa0865f0a31d0b884d14f5e7670/hardware/arduino/avr/cores/arduino/HID.cpp
05 01 // Usage page Generic desktop
09 02 // Usage Mouse
@ -34,6 +36,9 @@ a1 01 // Collection Application
c0 // End collection
00010101
00100101
input bytes (4 bytes)
0 - 0 data / 1 constant
1 - 0 array / 1 variable

View File

@ -2,29 +2,27 @@ from flask import Response
from flask import Flask
from flask import render_template
from flask import request
import threading
from flask_socketio import SocketIO
import argparse
import json
import struct
from hidkeycodes import hidkeycodes
from jskeycodes import jscodehidmap
lock = threading.Lock()
# initialize a flask object
app = Flask(__name__)
socketio = SocketIO(app)
hiddev = None
hidmouse = None
hidmouseabs = None
def hid_init():
global hiddev, hidmouse, hidmouseabs
global hiddev, hidmouseabs
hiddev = open('/dev/hidg0', 'rb+')
hidmouse = open('/dev/hidg1', 'rb+')
hidmouseabs = open('/dev/hidg2', 'rb+')
hidmouseabs = open('/dev/hidg1', 'rb+')
def hid_write(data):
@ -35,20 +33,6 @@ def hid_write(data):
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):
if hidmouseabs is None:
return False
@ -99,54 +83,57 @@ def get_hid_by_jscode(rawkeycode):
return hidkeycode, (hidkeyname is not None and "MOD" in hidkeyname)
@app.route("/")
def index():
return render_template("hid.html")
@app.route("/kvm.html")
def kvm():
return render_template("kvm.html")
@app.route("/mouse.html")
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")
@app.route("/hid/mouseabs", methods=["POST"])
def mouseabs():
mouseevent = json.loads(request.data)
print(mouseevent)
@app.route("/keyboard.html")
def keyboardIndex():
return render_template("keyboard.html")
@socketio.on('mouseEventRaw')
def handle_mouseEvent(data):
print(data)
btn = data[0]
x = data[1]
y = data[2]
wheel = data[3]
print("RAW Btn: {}, X: {}, Y: {}, W: {}".format(btn, x, y, wheel))
hid_mouse_writeabs(btn, x, y, wheel)
@socketio.on('mouseEvent')
def handle_mouseEvent(data):
mouseevent = json.loads(data)
print(mouseevent)
btn = mouseevent['btn']
x = mouseevent['x']
y = mouseevent['y']
wheel = mouseevent['wheel']
wheel = wheel if wheel >= 0 else 255-abs(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"])
def keypress():
keyevent = json.loads(request.data)
print("Raw data: {}".format(request.data))
@socketio.on('kbdEvent')
def handle_kbdEvent(data):
keyevent = json.loads(data)
print("Raw data: {}".format(data))
rawkeycode = keyevent['code']
hidkeycode, mod = get_hid_by_jscode(rawkeycode)
@ -162,8 +149,8 @@ def keypress():
except Exception as e:
print("Error sending HID message", e)
return Response("Press {}".format(hidkeycode), mimetype="text/plain")
hid_init()
# check to see if this is the main thread of execution
if __name__ == '__main__':
@ -177,12 +164,5 @@ if __name__ == '__main__':
help="# of frames used to construct the background model")
args = vars(ap.parse_args())
hid_init()
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()
use_reloader=False)

1
runhidinput.sh Executable file
View File

@ -0,0 +1 @@
uwsgi --http [::]:8001 --gevent 1000 --http-websockets --master --wsgi-file hidinput.py --callable app

1
runsockettest.sh Executable file
View File

@ -0,0 +1 @@
uwsgi --http :8001 --gevent 1000 --http-websockets --master --wsgi-file socketiotest.py --callable app

19
socketiotest.py Normal file
View File

@ -0,0 +1,19 @@
from flask import Flask, render_template
from flask_socketio import SocketIO
app = Flask(__name__)
socketio = SocketIO(app)
@app.route("/")
def index():
return render_template("socketio.html")
@socketio.on('my event')
def handle_my_custom_event(json):
print('received json: ' + str(json))
if __name__ == '__main__':
socketio.run(host="0.0.0.0", port=8001, app=app)

View File

@ -6,15 +6,7 @@
<style>
</style>
<script src="https://code.jquery.com/jquery-3.5.0.js"></script>
</head>
<body>
HID input service, POST data to /keyboard or /mouse <br/>
<div>
</div>
<br/>
Server response: <span></span>
<script src="//cdnjs.cloudflare.com/ajax/libs/socket.io/2.2.0/socket.io.js" integrity="sha256-yr4fRk/GU1ehYJPAs8P4JlTgu0Hdsp4ZKrx8bDEDC3I=" crossorigin="anonymous"></script>
<script>
function zapis(t) {
$("div").text(t);
@ -51,10 +43,7 @@ $(window).bind('keydown', function(event) {
dataType: "json"
});
$("span").text(ret.responseText);
console.log(ret);
}
var text = "";
@ -74,8 +63,53 @@ $(window).bind('keydown', function(event) {
previous = event.keyCode;
});
var btn=0;
var posX=0;
var posY=0;
var wheel=0;
var socket = io();
$(document).ready(function(){
$("canvas").mousedown(function(event){
btn=event.buttons;
handleMouse();
});
$("canvas").mouseup(function(event){
btn=event.buttons;
handleMouse();
});
$("canvas").mousemove(function(event){
posX=event.offsetX;
posY=event.offsetY;
handleMouse();
});
});
function handleMouse() {
$("span").text(btn +", "+ posX + ", " + posY);
sendMouse(btn, posX, posY, wheel);
}
function sendMouse(btn, x, y) {
var obj = {
x: x,
y: y,
btn: btn,
wheel: wheel,
}
socket.emit('mouseEvent', JSON.stringify(obj));
};
</script>
</head>
<body>
HID Remote Keyboard and mouse<br/>
<div></div>
<span></span><br/><br/>
<canvas width=1920 height=1080 style="border: 1px solid black" oncontextmenu="return false" onwheel='wheel=event.deltaY*-1; handleMouse(); wheel=0; return false;' ></canvas>
</body>
</html>

74
templates/keyboard.html Normal file
View File

@ -0,0 +1,74 @@
<!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>
<script src="//cdnjs.cloudflare.com/ajax/libs/socket.io/2.2.0/socket.io.js" integrity="sha256-yr4fRk/GU1ehYJPAs8P4JlTgu0Hdsp4ZKrx8bDEDC3I=" crossorigin="anonymous"></script>
</head>
<body>
HID input keyboard, POST data to /keyboard<br/>
<div>
</div>
<br/>
Server response: <span></span>
<script>
var socket = io();
function zapis(t) {
$("div").text(t);
}
var previous;
$(window).bind('keydown', function(event) {
event.preventDefault();
var str = String.fromCharCode(event.which).toLowerCase();
var ctrl = event.ctrlKey;
if (previous == 17) {
ctrl = true;
}
var obj = {
ctrlKey: ctrl,
shiftKey: event.shiftKey,
altKey: event.altKey,
which: event.which,
code: event.code,
str: str
}
if (event.which != 16 && event.which != 17 && event.which != 18) {
console.log(obj);
socket.emit('kbdEvent', JSON.stringify(obj));
}
var text = "";
if (ctrl) {
text = text + ' + Control';
}
if (event.shiftKey) {
text = text + ' + Shift';
}
if (event.altKey) {
text = text + ' + Alt';
}
text = text + ' + ' + str;
text = text.substr(3);
zapis(text);
previous = event.keyCode;
});
</script>
</body>
</html>

107
templates/kvm.html Normal file
View File

@ -0,0 +1,107 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Raspberry Pi KVM</title>
<style>
</style>
<script src="https://code.jquery.com/jquery-3.5.0.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/socket.io/2.2.0/socket.io.js" integrity="sha256-yr4fRk/GU1ehYJPAs8P4JlTgu0Hdsp4ZKrx8bDEDC3I=" crossorigin="anonymous"></script>
<script>
var socket = io();
var previous;
$(window).bind('keydown', function(event) {
event.preventDefault();
var str = String.fromCharCode(event.which).toLowerCase();
var ctrl = event.ctrlKey;
if (previous == 17) {
ctrl = true;
}
var obj = {
ctrlKey: ctrl,
shiftKey: event.shiftKey,
altKey: event.altKey,
which: event.which,
code: event.code,
str: str
}
if (event.which != 16 && event.which != 17 && event.which != 18) {
console.log(obj);
socket.emit('kbdEvent', JSON.stringify(obj));
}
var text = "";
if (ctrl) {
text = text + ' + Control';
}
if (event.shiftKey) {
text = text + ' + Shift';
}
if (event.altKey) {
text = text + ' + Alt';
}
text = text + ' + ' + str;
text = text.substr(3);
previous = event.keyCode;
});
var btn=0;
var posX=0;
var posY=0;
var wheel=0;
$(document).ready(function(){
$("img").mousedown(function(event){
btn=event.buttons;
handleMouse();
});
$("img").mouseup(function(event){
btn=event.buttons;
handleMouse();
});
$("img").mousemove(function(event){
posX=event.offsetX;
posY=event.offsetY;
handleMouse();
});
});
function handleMouse() {
$("span").text(btn +", "+ posX + ", " + posY);
sendMouse(btn, posX, posY, wheel);
}
function sendMouse(btn, x, y) {
var obj = {
x: x,
y: y,
btn: btn,
wheel: wheel,
}
var data = new Array(4);
data[0] = btn;
data[1] = x;
data[2] = y;
data[3] = wheel;
//socket.emit('mouseEvent', JSON.stringify(obj));
socket.emit('mouseEventRaw', data);
};
</script>
</head>
<body>
KVM<br/>
<span></span><br/><br/>
<img src="http://[2a01:510:d501:2800:1b8f:607e:9885:99c7]:8000/video_feed" draggable=false width=1920 height=1080 style="border: 1px solid black" oncontextmenu="return false" onwheel='wheel=event.deltaY*-1; handleMouse(); wheel=0; return false;' >
</body>
</html>

View File

@ -6,23 +6,20 @@
<style>
</style>
<script src="https://code.jquery.com/jquery-3.5.0.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/socket.io/2.2.0/socket.io.js" integrity="sha256-yr4fRk/GU1ehYJPAs8P4JlTgu0Hdsp4ZKrx8bDEDC3I=" crossorigin="anonymous"></script>
</head>
<body>
HID mouse service, POST data to /mouse <br/>
<div>
</div>
<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>
var btn=0;
var posX=0;
var posY=0;
var wheel=0;
var socket = io();
$(document).ready(function(){
@ -34,19 +31,16 @@ $(document).ready(function(){
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);
sendMouse(btn, posX, posY, wheel);
}
function sendMouse(btn, x, y) {
@ -54,22 +48,15 @@ function sendMouse(btn, x, y) {
x: x,
y: y,
btn: btn,
wheel: 0,
wheel: wheel,
}
var ret = $.ajax({
type: "POST",
url: "hid/mouseabs",
data: JSON.stringify(obj),
contentType: "application/json; charset=utf-8",
dataType: "json"
});
socket.emit('mouseEvent', JSON.stringify(obj));
};
</script>
<span></span><br/><br/>
<canvas width=500 height=500 style="border: 1px solid black" oncontextmenu="return false"></canvas>
<canvas width=1920 height=1080 style="border: 1px solid black" oncontextmenu="return false" onwheel='wheel=event.deltaY*-1; handleMouse(); wheel=0; return false;' ></canvas>
<!--<img src="placeholder.png" width=1920 height=1080 onmousemove='console.log("aaa");' />-->
</body>
</html>

14
templates/socketio.html Normal file
View File

@ -0,0 +1,14 @@
<html>
<body>
<script src="//cdnjs.cloudflare.com/ajax/libs/socket.io/2.2.0/socket.io.js" integrity="sha256-yr4fRk/GU1ehYJPAs8P4JlTgu0Hdsp4ZKrx8bDEDC3I=" crossorigin="anonymous"></script>
<script type="text/javascript" charset="utf-8">
var socket = io();
socket.on('connect', function() {
socket.emit('my event', {data: 'I\'m connected!'});
});
</script>
ahoj3
<input type="button" onClick="socket.emit('my event', 'test');" value="test" />
</body>
</html>