Remote-Mouse/src/core/routes/Sockets.py

108 lines
2.4 KiB
Python
Raw Permalink Normal View History

2020-06-29 23:31:57 +00:00
# Python imports
# Lib imports
import pyautogui
from flask import request, render_template
# App imports
2021-07-19 02:59:33 +00:00
from core import app, socketio # Get from __init__
2020-06-29 23:31:57 +00:00
from core.MessageHandler import MessageHandler # Get simple message processor
msgHandler = MessageHandler()
2021-08-03 03:35:19 +00:00
2021-07-19 02:59:33 +00:00
# Let piautogui make updates as quick as it can...
2021-08-03 03:35:19 +00:00
pyautogui.FAILSAFE = False # If we hit corner, that's ok
2021-07-19 02:59:33 +00:00
pyautogui.MINIMUM_DURATION = 0
2021-08-03 03:35:19 +00:00
pyautogui.PAUSE = 0
2021-07-19 02:59:33 +00:00
2020-06-29 23:31:57 +00:00
@app.route('/mouse-down')
2021-07-19 02:59:33 +00:00
@socketio.on('mouse_down')
2020-06-29 23:31:57 +00:00
def mouseDown(eve = None):
pyautogui.mouseDown()
return ""
@app.route('/mouse-up')
2021-07-19 02:59:33 +00:00
@socketio.on('mouse_up')
2020-06-29 23:31:57 +00:00
def mouseUp(eve = None):
pyautogui.mouseUp()
return ""
@app.route('/left-click')
2021-07-19 02:59:33 +00:00
@socketio.on('left_click')
2020-06-29 23:31:57 +00:00
def leftClick(eve = None):
pyautogui.click()
return ""
@app.route('/right-click')
2021-07-19 02:59:33 +00:00
@socketio.on('right_click')
2020-06-29 23:31:57 +00:00
def rightClick(eve = None):
pyautogui.click(button='right')
return ""
@app.route('/scroll-up')
2021-07-19 02:59:33 +00:00
@socketio.on('scroll_up')
2020-06-29 23:31:57 +00:00
def scrollUp(eve = None):
pyautogui.scroll(1)
return ""
@app.route('/scroll-down')
2021-07-19 02:59:33 +00:00
@socketio.on('scroll_down')
2020-06-29 23:31:57 +00:00
def scrollDown(eve = None):
pyautogui.scroll(-1)
return ""
2020-07-02 02:55:56 +00:00
@app.route('/press-enter')
2021-07-19 02:59:33 +00:00
@socketio.on('press_enter')
2020-07-02 02:55:56 +00:00
def pressEnter(eve = None):
pyautogui.press("enter")
return ""
2020-07-28 19:10:17 +00:00
@app.route('/press-back')
2021-07-19 02:59:33 +00:00
@socketio.on('press_back')
2020-07-28 19:10:17 +00:00
def pressBack(eve = None):
pyautogui.press("backspace")
return ""
2020-06-29 23:31:57 +00:00
2021-07-19 02:59:33 +00:00
@socketio.on('update_coords')
def updateCoords(message):
try:
parts = message.split(",")
x = float( parts[0] )
y = float( parts[1] )
# print(str(x) + "," + str(y))
pyautogui.moveRel(x, y);
except Exception as e:
print( repr(e) )
2021-08-03 03:35:19 +00:00
# @app.route('/update-coords/xy/<m1>/<m2>')
# @socketio.on('update_coords', namespace='/socket.io')
# def updateCoords(m1 = None, m2 = None):
# if not m2:
# try:
# parts = m1.split(",")
# x = round(float( parts[0] ), 2)
# y = round(float( parts[1] ), 2)
# print(str(x) + "," + str(y))
# pyautogui.moveRel(x, y);
# except Exception as e:
# print(repr(e))
# else:
# try:
# x = round(float(m1), 2)
# y = round(float(m2), 2)
# print(str(x) + "," + str(y))
# pyautogui.moveRel(x, y);
# except Exception as e:
# print(repr(e))
#
# return ""