Improved move detection
This commit is contained in:
parent
16c4d3f1dc
commit
93190587a6
|
@ -52,12 +52,26 @@ def getCoords():
|
||||||
def updateCoords(message):
|
def updateCoords(message):
|
||||||
try:
|
try:
|
||||||
parts = message.split(",")
|
parts = message.split(",")
|
||||||
x = float( parts[0] )
|
x = float( parts[0] )
|
||||||
y = float( parts[1] )
|
y = float( parts[1] )
|
||||||
|
# print(str(x) + "," + str(y))
|
||||||
pyautogui.moveRel(x, y);
|
pyautogui.moveRel(x, y);
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print( repr(e) )
|
print( repr(e) )
|
||||||
|
|
||||||
|
@app.route('/update-coords/xy/<x>/<y>')
|
||||||
|
def updateCoords2(x, y):
|
||||||
|
try:
|
||||||
|
# print(x + "," + y)
|
||||||
|
pyautogui.moveRel(float(x), float(y));
|
||||||
|
return "{}"
|
||||||
|
except Exception as e:
|
||||||
|
print( repr(e) )
|
||||||
|
return render_template('error.html',
|
||||||
|
title='Error!',
|
||||||
|
message='Key is not a valid input...')
|
||||||
|
|
||||||
|
|
||||||
@app.route('/send-key', methods=['GET', 'POST'])
|
@app.route('/send-key', methods=['GET', 'POST'])
|
||||||
def sendKey():
|
def sendKey():
|
||||||
pyautogui.doubleClick()
|
pyautogui.doubleClick()
|
||||||
|
|
|
@ -43,12 +43,6 @@ input {
|
||||||
z-index: -999;
|
z-index: -999;
|
||||||
}
|
}
|
||||||
|
|
||||||
#canvas {
|
|
||||||
width: 100%;
|
|
||||||
min-height: 65em;
|
|
||||||
background-color: rgba(56, 56, 56, 0.67);
|
|
||||||
}
|
|
||||||
|
|
||||||
#singleClickBtn, #doubleClickBtn {
|
#singleClickBtn, #doubleClickBtn {
|
||||||
background-color: #62c462;
|
background-color: #62c462;
|
||||||
border-style: dashed;
|
border-style: dashed;
|
||||||
|
@ -60,9 +54,7 @@ input {
|
||||||
}
|
}
|
||||||
|
|
||||||
#singleClickBtn:hover,
|
#singleClickBtn:hover,
|
||||||
#doubleClickBtn:hover,
|
#doubleClickBtn:hover {
|
||||||
#singleClickBtn:active,
|
|
||||||
#doubleClickBtn:active {
|
|
||||||
background-color: rgba(0, 232, 255, 0.5);
|
background-color: rgba(0, 232, 255, 0.5);
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
const doAjax = (actionPath, data, action) => {
|
const doAjax = async (actionPath, data, action, postType = "POST") => {
|
||||||
let xhttp = new XMLHttpRequest();
|
let xhttp = new XMLHttpRequest();
|
||||||
xhttp.open("POST", actionPath, true);
|
xhttp.open(postType, actionPath, true);
|
||||||
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
|
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
|
||||||
// Force return to be JSON NOTE: Use application/xml to force XML
|
// Force return to be JSON NOTE: Use application/xml to force XML
|
||||||
xhttp.overrideMimeType('application/json');
|
xhttp.overrideMimeType('application/json');
|
||||||
|
|
|
@ -1,133 +1,79 @@
|
||||||
const socket = io();
|
const socket = io();
|
||||||
|
let px = 0;
|
||||||
|
let py = 0;
|
||||||
|
|
||||||
|
|
||||||
socket.on('connect', function() {
|
socket.on('connect', function() {
|
||||||
console.log("Websocket connected...");
|
console.log("Websocket connected...");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// When true, moving the mouse updates coords
|
$(function () {
|
||||||
const canvas = document.getElementById("canvas");
|
$.mousedirection();
|
||||||
let isDragging = false;
|
$("#canvas").on("mousedirection", function (e) {
|
||||||
let runUpdate = false;
|
if (e.direction == "up") {
|
||||||
let xLast = 0;
|
|
||||||
let yLast = 0;
|
|
||||||
let mod = 2;
|
|
||||||
let px = 0;
|
|
||||||
let py = 0;
|
|
||||||
let x1 = 0;
|
|
||||||
let y1 = 0;
|
|
||||||
let x2 = 0;
|
|
||||||
let y2 = 0;
|
|
||||||
let m = undefined; // slope value
|
|
||||||
|
|
||||||
|
|
||||||
canvas.addEventListener('touchstart', e => { onPress(e); });
|
|
||||||
canvas.addEventListener('mousedown', e => { onPress(e); });
|
|
||||||
canvas.addEventListener('touchmove', e => { onMoveing(e); });
|
|
||||||
canvas.addEventListener('mousemove', e => { onMoveing(e); });
|
|
||||||
canvas.addEventListener('touchend', e => { onRelease(e); });
|
|
||||||
canvas.addEventListener('mouseup', e => { onRelease(e); });
|
|
||||||
|
|
||||||
|
|
||||||
const onPress = (e) => {
|
|
||||||
isDragging = true;
|
|
||||||
runUpdate = true;
|
|
||||||
xLast = e.offsetX;
|
|
||||||
yLast = e.offsetY;
|
|
||||||
updateText(xLast, yLast);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const onMoveing = (e) => {
|
|
||||||
if (isDragging === true) {
|
|
||||||
x1 = xLast;
|
|
||||||
y1 = yLast;
|
|
||||||
|
|
||||||
if (e.type === 'mousemove') {
|
|
||||||
x2 = e.offsetX;
|
|
||||||
y2 = e.offsetY;
|
|
||||||
xLast = e.offsetX;
|
|
||||||
yLast = e.offsetY;
|
|
||||||
} else if (e.type === 'touchmove') {
|
|
||||||
x2 = parseInt(e.touches[0].clientX, 10);
|
|
||||||
y2 = parseInt(e.touches[0].clientY, 10);
|
|
||||||
xLast = parseInt(e.touches[0].clientX, 10);
|
|
||||||
yLast = parseInt(e.touches[0].clientY, 10);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Calculate the delta of the points
|
|
||||||
if (x2 > x1) {
|
|
||||||
px = mod // Is growing
|
|
||||||
} else {
|
|
||||||
px = -mod // Is shrinking
|
|
||||||
}
|
|
||||||
|
|
||||||
if (y2 > y1) {
|
|
||||||
py = mod // Is growing
|
|
||||||
} else {
|
|
||||||
py = -mod // Is shrinking
|
|
||||||
}
|
|
||||||
|
|
||||||
m = (y2-y1)/(x2-x1)
|
|
||||||
if (m === undefined) {
|
|
||||||
py = 0;
|
|
||||||
} else if (!isFinite(m)) {
|
|
||||||
px = 0;
|
px = 0;
|
||||||
}
|
py = -1;
|
||||||
|
} else if (e.direction == "down") {
|
||||||
if ( (m > 0.05 && m <= 1) && (m > -0.05 && m >= -1) ) {
|
px = 0;
|
||||||
|
py = 1;
|
||||||
|
} else if (e.direction == "left") {
|
||||||
|
px = -1;
|
||||||
py = 0;
|
py = 0;
|
||||||
|
} else if (e.direction == "right") {
|
||||||
|
px = 1;
|
||||||
|
py = 0;
|
||||||
|
} else if (e.direction == "top-left") {
|
||||||
|
px = -1;
|
||||||
|
py = -1;
|
||||||
|
} else if (e.direction == "top-right") {
|
||||||
|
px = 1;
|
||||||
|
py = -1;
|
||||||
|
} else if (e.direction == "bottom-left") {
|
||||||
|
px = -1;
|
||||||
|
py = 1;
|
||||||
|
} else if (e.direction == "bottom-right") {
|
||||||
|
px = 1;
|
||||||
|
py = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
socket.emit('update_coords', x2 + "," + y2);
|
updateText (px, py);
|
||||||
}
|
});
|
||||||
}
|
});
|
||||||
|
|
||||||
|
|
||||||
const onRelease = (e) => {
|
|
||||||
if (isDragging === true) {
|
|
||||||
isDragging = false;
|
|
||||||
mod = 2
|
|
||||||
xLast = 0;
|
|
||||||
yLast = 0;
|
|
||||||
px = 0;
|
|
||||||
py = 0;
|
|
||||||
updateText(px, py);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
function updateText (px, py) {
|
||||||
const updateText = (x, y) => {
|
const coordsTxt = "X coords: " + px + ", Y coords: " + py;
|
||||||
const coordsTxt = "X coords: " + x + ", Y coords: " + y;
|
|
||||||
document.getElementById("cordsText").innerText = coordsTxt;
|
document.getElementById("cordsText").innerText = coordsTxt;
|
||||||
|
// doAjax("/update-coords/xy/" + px + "/" + py, "" , "update-coords", "GET");
|
||||||
|
socket.emit('update_coords', px + "," + py);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Touch events converted to mouse events
|
||||||
|
function touchHandler(event) {
|
||||||
|
let touches = event.changedTouches,
|
||||||
|
first = touches[0],
|
||||||
|
type = "";
|
||||||
|
|
||||||
|
switch(event.type) {
|
||||||
|
case "touchstart": type = "mousedown"; break;
|
||||||
|
case "touchmove": type = "mousemove"; break;
|
||||||
|
case "touchend": type = "mouseup"; break;
|
||||||
|
default: return;
|
||||||
|
}
|
||||||
|
|
||||||
// Click events
|
let simulatedEvent = document.createEvent("MouseEvent");
|
||||||
document.getElementById("singleClickBtn").addEventListener('mouseup', e => { onSingleClick(e); });
|
simulatedEvent.initMouseEvent(type, true, true, window, 1,
|
||||||
document.getElementById("singleClickBtn").addEventListener('touchend', e => { onSingleClick(e); });
|
first.screenX, first.screenY,
|
||||||
document.getElementById("doubleClickBtn").addEventListener('mouseup', e => { onDoubleClick(e); });
|
first.clientX, first.clientY, false,
|
||||||
document.getElementById("doubleClickBtn").addEventListener('touchend', e => { onDoubleClick(e); });
|
false, false, false, 0/*left*/, null);
|
||||||
|
|
||||||
const onSingleClick = (e) => {
|
first.target.dispatchEvent(simulatedEvent);
|
||||||
doAjax("/single-click", "ref=null", "singleClick");
|
event.preventDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
const onDoubleClick = (e) => {
|
document.addEventListener("touchstart", touchHandler, true);
|
||||||
doAjax("/double-click", "ref=null", "doubleClick");
|
document.addEventListener("touchmove", touchHandler, true);
|
||||||
}
|
document.addEventListener("touchend", touchHandler, true);
|
||||||
|
document.addEventListener("touchcancel", touchHandler, true);
|
||||||
|
|
||||||
|
|
||||||
// Key input events
|
|
||||||
// document.getElementById("sendKeysField").addEventListener('input', e => { onSendKeys(e); });
|
|
||||||
// document.getElementById("sendKeysField").addEventListener('change', e => { onSendKeys(e); });
|
|
||||||
document.getElementById("sendKeysBtn").addEventListener('mouseup', e => { onSendKeys(e); });
|
|
||||||
document.getElementById("sendKeysBtn").addEventListener('touchend', e => { onSendKeys(e); });
|
|
||||||
|
|
||||||
const onSendKeys = (e) => {
|
|
||||||
let target = document.getElementById("sendKeysField");
|
|
||||||
const text = target.value;
|
|
||||||
doAjax("/send-key", "text=" + text, "sendKeys");
|
|
||||||
target.value = "";
|
|
||||||
}
|
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,47 @@
|
||||||
|
/**
|
||||||
|
* jQuery Mouse Direction Plugin
|
||||||
|
* @version: 1.1
|
||||||
|
* @author Hasin Hayder [hasin@leevio.com | http://hasin.me]
|
||||||
|
*/
|
||||||
|
(function ($) {
|
||||||
|
var options = {};
|
||||||
|
var oldx = 0;
|
||||||
|
var oldy = 0;
|
||||||
|
var direction="";
|
||||||
|
$.mousedirection = function (opts) {
|
||||||
|
var defaults = {
|
||||||
|
};
|
||||||
|
options = $.extend(defaults, opts);
|
||||||
|
$(document).bind("mousemove", function (e) {
|
||||||
|
var activeElement = e.target || e.srcElement;
|
||||||
|
if (e.pageX > oldx && e.pageY > oldy) {
|
||||||
|
direction="bottom-right";
|
||||||
|
}
|
||||||
|
else if (e.pageX > oldx && e.pageY < oldy) {
|
||||||
|
direction="top-right";
|
||||||
|
}
|
||||||
|
else if (e.pageX < oldx && e.pageY < oldy) {
|
||||||
|
direction="top-left";
|
||||||
|
}
|
||||||
|
else if (e.pageX < oldx && e.pageY > oldy) {
|
||||||
|
direction="bottom-left";
|
||||||
|
}
|
||||||
|
else if (e.pageX > oldx && e.pageY == oldy) {
|
||||||
|
direction="right";
|
||||||
|
}
|
||||||
|
else if (e.pageX == oldx && e.pageY > oldy) {
|
||||||
|
direction="down";
|
||||||
|
}
|
||||||
|
else if (e.pageX == oldx && e.pageY < oldy) {
|
||||||
|
direction="up";
|
||||||
|
}
|
||||||
|
else if (e.pageX < oldx && e.pageY == oldy) {
|
||||||
|
direction="left";
|
||||||
|
}
|
||||||
|
$(activeElement).trigger(direction);
|
||||||
|
$(activeElement).trigger({type:"mousedirection",direction:direction});
|
||||||
|
oldx=e.pageX;
|
||||||
|
oldy=e.pageY;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})(jQuery);
|
|
@ -1,7 +1,7 @@
|
||||||
{% extends "layout.html" %}
|
{% extends "layout.html" %}
|
||||||
|
|
||||||
{% block body_header_additional %}
|
{% block body_header_additional %}
|
||||||
<script src="{{url_for('static', filename='js/libs/socket.io.js')}}"></script>
|
<script src="{{url_for('static', filename='js/libs/jquery-1.12.4.min.js')}}"></script>
|
||||||
{% endblock body_header_additional %}
|
{% endblock body_header_additional %}
|
||||||
|
|
||||||
{% block body_content %}
|
{% block body_content %}
|
||||||
|
@ -20,12 +20,14 @@
|
||||||
<button id="sendKeysBtn" class="btn btn-success">Send</button>
|
<button id="sendKeysBtn" class="btn btn-success">Send</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div id="canvas" class="container-auto">
|
<div class="container-auto">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col justify-content-center text-center">
|
<div class="col justify-content-center text-center">
|
||||||
<div id="cordsText" style="font-size: 280%;">
|
<div id="cordsText" style="font-size: 280%;">
|
||||||
X coords: 0, Y coords: 0
|
X coords: 0, Y coords: 0
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<canvas id="canvas" width="650" height="650" style="border:1px solid #c3c3c3;"></canvas>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -36,7 +38,8 @@
|
||||||
{% endblock body_footer_additional %}
|
{% endblock body_footer_additional %}
|
||||||
|
|
||||||
{% block body_scripts_additional %}
|
{% block body_scripts_additional %}
|
||||||
|
<script src="{{url_for('static', filename='js/libs/socket.io.js')}}"></script>
|
||||||
|
<script src="{{url_for('static', filename='js/libs/jquery.mousedirection.js')}}"></script>
|
||||||
<script src="{{url_for('static', filename='js/ajax.js')}}"></script>
|
<script src="{{url_for('static', filename='js/ajax.js')}}"></script>
|
||||||
<script src="{{url_for('static', filename='js/events.js')}}"></script>
|
<script src="{{url_for('static', filename='js/events.js')}}"></script>
|
||||||
<!-- <script src="{{url_for('static', filename='js/draging.js')}}"></script> -->
|
|
||||||
{% endblock body_scripts_additional %}
|
{% endblock body_scripts_additional %}
|
||||||
|
|
|
@ -6,8 +6,9 @@
|
||||||
|
|
||||||
|
|
||||||
function main() {
|
function main() {
|
||||||
source "../venv/bin/activate"
|
source "/home/abaddon/Portable_Apps/py-venvs/remotemouse-venv/bin/activate"
|
||||||
# Note can replace 127.0.0.1 with 0.0.0.0 to make it 'network/internet' accessable...
|
# Note can replace 127.0.0.1 with 0.0.0.0 to make it 'network/internet' accessable...
|
||||||
gunicorn wsgi:app -b 127.0.0.1:8088 # <module>:<app> IE <file>:<flask app variable>
|
# Note: NEED -k eventlet for this to work! I spent too many hours on this...
|
||||||
|
gunicorn wsgi:app -b 127.0.0.1:8088 -k eventlet # <module>:<app> IE <file>:<flask app variable>
|
||||||
}
|
}
|
||||||
main $@;
|
main $@;
|
||||||
|
|
|
@ -10,6 +10,7 @@ function main() {
|
||||||
cd "${SCRIPTPATH}"
|
cd "${SCRIPTPATH}"
|
||||||
echo "Working Dir: " $(pwd)
|
echo "Working Dir: " $(pwd)
|
||||||
mkdir /tmp/apps
|
mkdir /tmp/apps
|
||||||
../venv/bin/gunicorn --bind unix:/tmp/apps/remoteconn.sock wsgi:app
|
/home/abaddon/Portable_Apps/py-venvs/remotemouse-venv/bin/gunicorn \
|
||||||
|
--bind unix:/tmp/apps/remoteconn.sock wsgi:app
|
||||||
}
|
}
|
||||||
main $@;
|
main $@;
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
from core import socketio, app
|
from core import app, socketio
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
socketio.run(app, host="127.0.0.1", port="8088")
|
socketio.run(app, host="127.0.0.1", port="8088")
|
||||||
# app.run(debug=True)
|
|
||||||
|
|
Loading…
Reference in New Issue