Compare commits
26 Commits
Author | SHA1 | Date | |
---|---|---|---|
844f76e2c2 | |||
43b82fd669 | |||
0dbf3f9b7a | |||
42ec2611e3 | |||
beaad49558 | |||
44d01c0127 | |||
cf5ee01a9c | |||
0416f32744 | |||
009d008b5b | |||
19086199c0 | |||
50ab6c43fc | |||
33bc12cb8a | |||
2a22d0b2bf | |||
ad8a962be8 | |||
6aaa2f5b0d | |||
11119bb1cb | |||
1fa5e4be16 | |||
30e6b30893 | |||
dcea5e5dca | |||
bbbf8cbbf6 | |||
6c1bd1235d | |||
478cb9c202 | |||
deb2139d96 | |||
12644f1e39 | |||
fb2c4b4874 | |||
ce4842d93e |
@ -9,7 +9,6 @@ echo "" > UDC
|
|||||||
echo "Clean up configs"
|
echo "Clean up configs"
|
||||||
rm configs/c.1/hid.kbd0
|
rm configs/c.1/hid.kbd0
|
||||||
rm configs/c.1/hid.mouse0
|
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.disk1
|
||||||
rm configs/c.1/mass_storage.cdrom1
|
rm configs/c.1/mass_storage.cdrom1
|
||||||
|
|
||||||
@ -19,7 +18,6 @@ rmdir configs/c.1
|
|||||||
echo "Clean up functions"
|
echo "Clean up functions"
|
||||||
rmdir functions/hid.kbd0
|
rmdir functions/hid.kbd0
|
||||||
rmdir functions/hid.mouse0
|
rmdir functions/hid.mouse0
|
||||||
rmdir functions/hid.mouse1
|
|
||||||
rmdir functions/mass_storage.disk1
|
rmdir functions/mass_storage.disk1
|
||||||
rmdir functions/mass_storage.cdrom1
|
rmdir functions/mass_storage.cdrom1
|
||||||
|
|
||||||
|
@ -5,7 +5,19 @@ gserial=$(awk '/Serial/ { print $3 }' /proc/cpuinfo)
|
|||||||
gmanufacturer="Petrkr.NET"
|
gmanufacturer="Petrkr.NET"
|
||||||
gproduct="rPi KVM"
|
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="$MOUSE0\\x05\\x01\\x09\\x02" # Usage generic desktop, Usage mouse
|
MOUSE0="$MOUSE0\\x05\\x01\\x09\\x02" # Usage generic desktop, Usage mouse
|
||||||
MOUSE0="$MOUSE0\\xa1\\x01\\x09\\x01" # Collection App, Usage Pointer
|
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\\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\\x81\\x02" # Input data, variable, absolute
|
||||||
MOUSE0="$MOUSE0\\x05\\x01" # Usage page generic desktop
|
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\\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 Physical
|
||||||
MOUSE0="$MOUSE0\\xc0" # End collection Application
|
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/
|
cd /sys/kernel/config/usb_gadget/
|
||||||
mkdir -p $gname
|
mkdir -p $gname
|
||||||
cd $gname
|
cd $gname
|
||||||
@ -66,36 +64,30 @@ mkdir -p functions/hid.kbd0
|
|||||||
echo 1 > functions/hid.kbd0/protocol
|
echo 1 > functions/hid.kbd0/protocol
|
||||||
echo 1 > functions/hid.kbd0/subclass
|
echo 1 > functions/hid.kbd0/subclass
|
||||||
echo 8 > functions/hid.kbd0/report_length
|
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
|
mkdir -p functions/hid.mouse0
|
||||||
echo 2 > functions/hid.mouse0/protocol
|
echo 2 > functions/hid.mouse0/protocol
|
||||||
echo 1 > functions/hid.mouse0/subclass
|
echo 1 > functions/hid.mouse0/subclass
|
||||||
echo 8 > functions/hid.mouse0/report_length
|
echo 8 > functions/hid.mouse0/report_length
|
||||||
echo -ne $MOUSE0 > functions/hid.mouse0/report_desc
|
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"
|
echo " Mass storage"
|
||||||
mkdir -p functions/mass_storage.disk1
|
mkdir -p functions/mass_storage.disk1
|
||||||
|
echo "RPi KVM DISK" > functions/mass_storage.disk1/lun.0/inquiry_string
|
||||||
|
|
||||||
echo " CD-ROM"
|
echo " CD-ROM"
|
||||||
mkdir -p functions/mass_storage.cdrom1
|
mkdir -p functions/mass_storage.cdrom1
|
||||||
echo 1 > functions/mass_storage.cdrom1/lun.0/cdrom
|
echo 1 > functions/mass_storage.cdrom1/lun.0/cdrom
|
||||||
echo 1 > functions/mass_storage.cdrom1/lun.0/removable
|
echo 1 > functions/mass_storage.cdrom1/lun.0/removable
|
||||||
|
echo "RPi KVM CDROM" > functions/mass_storage.cdrom1/lun.0/inquiry_string
|
||||||
|
|
||||||
|
|
||||||
echo "Activating gadgeds"
|
echo "Activating gadgeds"
|
||||||
ln -s functions/hid.kbd0 configs/c.1/
|
ln -s functions/hid.kbd0 configs/c.1/
|
||||||
ln -s functions/hid.mouse0 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.disk1 configs/c.1/
|
||||||
ln -s functions/mass_storage.cdrom1 configs/c.1/
|
ln -s functions/mass_storage.cdrom1 configs/c.1/
|
||||||
|
|
||||||
@ -106,4 +98,3 @@ ls /sys/class/udc > UDC
|
|||||||
echo "Change permissions"
|
echo "Change permissions"
|
||||||
chgrp input /dev/hidg0; chmod 660 /dev/hidg0
|
chgrp input /dev/hidg0; chmod 660 /dev/hidg0
|
||||||
chgrp input /dev/hidg1; chmod 660 /dev/hidg1
|
chgrp input /dev/hidg1; chmod 660 /dev/hidg1
|
||||||
chgrp input /dev/hidg2; chmod 660 /dev/hidg2
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
https://github.com/arduino/Arduino/blob/da9641410a4b8fa0865f0a31d0b884d14f5e7670/hardware/arduino/avr/cores/arduino/HID.cpp
|
||||||
|
|
||||||
05 01 // Usage page Generic desktop
|
05 01 // Usage page Generic desktop
|
||||||
09 02 // Usage Mouse
|
09 02 // Usage Mouse
|
||||||
|
|
||||||
@ -34,6 +36,9 @@ a1 01 // Collection Application
|
|||||||
c0 // End collection
|
c0 // End collection
|
||||||
|
|
||||||
|
|
||||||
|
00010101
|
||||||
|
00100101
|
||||||
|
|
||||||
input bytes (4 bytes)
|
input bytes (4 bytes)
|
||||||
0 - 0 data / 1 constant
|
0 - 0 data / 1 constant
|
||||||
1 - 0 array / 1 variable
|
1 - 0 array / 1 variable
|
||||||
|
98
hidinput.py
98
hidinput.py
@ -2,29 +2,27 @@ from flask import Response
|
|||||||
from flask import Flask
|
from flask import Flask
|
||||||
from flask import render_template
|
from flask import render_template
|
||||||
from flask import request
|
from flask import request
|
||||||
import threading
|
from flask_socketio import SocketIO
|
||||||
import argparse
|
import argparse
|
||||||
import json
|
import json
|
||||||
|
import struct
|
||||||
|
|
||||||
from hidkeycodes import hidkeycodes
|
from hidkeycodes import hidkeycodes
|
||||||
from jskeycodes import jscodehidmap
|
from jskeycodes import jscodehidmap
|
||||||
|
|
||||||
|
|
||||||
lock = threading.Lock()
|
|
||||||
|
|
||||||
# initialize a flask object
|
# initialize a flask object
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
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):
|
||||||
@ -35,20 +33,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
|
||||||
@ -99,54 +83,57 @@ 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")
|
||||||
|
|
||||||
|
@app.route("/kvm.html")
|
||||||
|
def kvm():
|
||||||
|
return render_template("kvm.html")
|
||||||
|
|
||||||
@app.route("/mouse.html")
|
@app.route("/mouse.html")
|
||||||
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)
|
|
||||||
|
|
||||||
|
|
||||||
|
@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']
|
btn = mouseevent['btn']
|
||||||
x = mouseevent['x']
|
x = mouseevent['x']
|
||||||
y = mouseevent['y']
|
y = mouseevent['y']
|
||||||
wheel = mouseevent['wheel']
|
wheel = mouseevent['wheel']
|
||||||
|
wheel = wheel if wheel >= 0 else 255-abs(wheel)
|
||||||
|
|
||||||
print("X: {}, Y: {}".format(x, y))
|
print("X: {}, Y: {}".format(x, y))
|
||||||
|
|
||||||
hid_mouse_writeabs(btn, x, y, wheel)
|
hid_mouse_writeabs(btn, x, y, wheel)
|
||||||
|
|
||||||
return Response("", mimetype="text/plain")
|
|
||||||
|
|
||||||
|
@socketio.on('kbdEvent')
|
||||||
@app.route("/hid/keyboard", methods=["POST"])
|
def handle_kbdEvent(data):
|
||||||
def keypress():
|
keyevent = json.loads(data)
|
||||||
keyevent = json.loads(request.data)
|
print("Raw data: {}".format(data))
|
||||||
print("Raw data: {}".format(request.data))
|
|
||||||
|
|
||||||
rawkeycode = keyevent['code']
|
rawkeycode = keyevent['code']
|
||||||
hidkeycode, mod = get_hid_by_jscode(rawkeycode)
|
hidkeycode, mod = get_hid_by_jscode(rawkeycode)
|
||||||
@ -162,8 +149,8 @@ def keypress():
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("Error sending HID message", 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
|
# check to see if this is the main thread of execution
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
@ -177,12 +164,5 @@ if __name__ == '__main__':
|
|||||||
help="# of frames used to construct the background model")
|
help="# of frames used to construct the background model")
|
||||||
args = vars(ap.parse_args())
|
args = vars(ap.parse_args())
|
||||||
|
|
||||||
hid_init()
|
|
||||||
|
|
||||||
app.run(host=args["ip"], port=args["port"], debug=True,
|
app.run(host=args["ip"], port=args["port"], debug=True,
|
||||||
threaded=True, use_reloader=False)
|
use_reloader=False)
|
||||||
|
|
||||||
# Clean up
|
|
||||||
if hiddev is not None:
|
|
||||||
print("Closing hid")
|
|
||||||
hiddev.close()
|
|
||||||
|
1
runhidinput.sh
Executable file
1
runhidinput.sh
Executable file
@ -0,0 +1 @@
|
|||||||
|
uwsgi --http [::]:8001 --gevent 1000 --http-websockets --master --wsgi-file hidinput.py --callable app
|
1
runsockettest.sh
Executable file
1
runsockettest.sh
Executable file
@ -0,0 +1 @@
|
|||||||
|
uwsgi --http :8001 --gevent 1000 --http-websockets --master --wsgi-file socketiotest.py --callable app
|
19
socketiotest.py
Normal file
19
socketiotest.py
Normal 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)
|
||||||
|
|
@ -6,76 +6,110 @@
|
|||||||
<style>
|
<style>
|
||||||
</style>
|
</style>
|
||||||
<script src="https://code.jquery.com/jquery-3.5.0.js"></script>
|
<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>
|
||||||
|
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);
|
||||||
|
|
||||||
|
var ret = $.ajax({
|
||||||
|
type: "POST",
|
||||||
|
url: "hid/keyboard",
|
||||||
|
data: JSON.stringify(obj),
|
||||||
|
contentType: "application/json; charset=utf-8",
|
||||||
|
dataType: "json"
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
});
|
||||||
|
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>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
HID input service, POST data to /keyboard or /mouse <br/>
|
HID Remote Keyboard and mouse<br/>
|
||||||
<div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<br/>
|
<div></div>
|
||||||
Server response: <span></span>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
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);
|
|
||||||
|
|
||||||
var ret = $.ajax({
|
|
||||||
type: "POST",
|
|
||||||
url: "hid/keyboard",
|
|
||||||
data: JSON.stringify(obj),
|
|
||||||
contentType: "application/json; charset=utf-8",
|
|
||||||
dataType: "json"
|
|
||||||
});
|
|
||||||
|
|
||||||
$("span").text(ret.responseText);
|
|
||||||
console.log(ret);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
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>
|
|
||||||
|
|
||||||
|
<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>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
74
templates/keyboard.html
Normal file
74
templates/keyboard.html
Normal 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
107
templates/kvm.html
Normal 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>
|
@ -6,23 +6,20 @@
|
|||||||
<style>
|
<style>
|
||||||
</style>
|
</style>
|
||||||
<script src="https://code.jquery.com/jquery-3.5.0.js"></script>
|
<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>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
HID mouse service, POST data to /mouse <br/>
|
HID mouse service, POST data to /mouse <br/>
|
||||||
<div>
|
<div>
|
||||||
</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>
|
<script>
|
||||||
|
|
||||||
var btn=0;
|
var btn=0;
|
||||||
var posX=0;
|
var posX=0;
|
||||||
var posY=0;
|
var posY=0;
|
||||||
|
var wheel=0;
|
||||||
|
|
||||||
|
var socket = io();
|
||||||
|
|
||||||
$(document).ready(function(){
|
$(document).ready(function(){
|
||||||
|
|
||||||
@ -34,19 +31,16 @@ $(document).ready(function(){
|
|||||||
btn=event.buttons;
|
btn=event.buttons;
|
||||||
handleMouse();
|
handleMouse();
|
||||||
});
|
});
|
||||||
|
$("canvas").mousemove(function(event){
|
||||||
$("canvas").mousemove(function(event){
|
posX=event.offsetX;
|
||||||
// sendMouse(0, event.originalEvent.movementX, event.originalEvent.movementY);
|
posY=event.offsetY;
|
||||||
posX=event.offsetX;
|
handleMouse();
|
||||||
posY=event.offsetY;
|
});
|
||||||
handleMouse();
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
function handleMouse() {
|
function handleMouse() {
|
||||||
$("span").text(btn +", "+ posX + ", " + posY);
|
$("span").text(btn +", "+ posX + ", " + posY);
|
||||||
sendMouse(btn, posX, posY);
|
sendMouse(btn, posX, posY, wheel);
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendMouse(btn, x, y) {
|
function sendMouse(btn, x, y) {
|
||||||
@ -54,22 +48,15 @@ function sendMouse(btn, x, y) {
|
|||||||
x: x,
|
x: x,
|
||||||
y: y,
|
y: y,
|
||||||
btn: btn,
|
btn: btn,
|
||||||
wheel: 0,
|
wheel: wheel,
|
||||||
}
|
}
|
||||||
|
|
||||||
var ret = $.ajax({
|
socket.emit('mouseEvent', JSON.stringify(obj));
|
||||||
type: "POST",
|
|
||||||
url: "hid/mouseabs",
|
|
||||||
data: JSON.stringify(obj),
|
|
||||||
contentType: "application/json; charset=utf-8",
|
|
||||||
dataType: "json"
|
|
||||||
});
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
<span></span><br/><br/>
|
<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");' />-->
|
<!--<img src="placeholder.png" width=1920 height=1080 onmousemove='console.log("aaa");' />-->
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
14
templates/socketio.html
Normal file
14
templates/socketio.html
Normal 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>
|
Loading…
Reference in New Issue
Block a user