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

87 lines
2.9 KiB
Python
Raw Normal View History

2020-05-28 18:07:53 +00:00
# Python imports
2020-07-28 19:10:17 +00:00
import subprocess
2020-05-28 18:07:53 +00:00
# Lib imports
import pyautogui
from flask import request, render_template
2020-06-12 03:38:20 +00:00
2020-05-28 18:07:53 +00:00
# App imports
2020-06-12 03:38:20 +00:00
from core import app, socketio # Get from __init__
2020-05-28 18:07:53 +00:00
from core.MessageHandler import MessageHandler # Get simple message processor
msgHandler = MessageHandler()
TITLE = app.config['TITLE']
2020-06-12 03:38:20 +00:00
pyautogui.FAILSAFE = False # If we hit corner, that's ok
# Let piautogui make updates as quick as it can...
pyautogui.MINIMUM_DURATION = 0
pyautogui.PAUSE = 0
2020-05-28 18:07:53 +00:00
2020-06-29 23:01:45 +00:00
@app.route('/')
2020-05-28 18:07:53 +00:00
def home():
if request.method == 'GET':
return render_template('index.html',
title=TITLE)
return render_template('error.html',
title='Error!',
message='Must use GET request type...')
2020-07-28 19:10:17 +00:00
@app.route('/sound-manager')
def soundManager():
if request.method == 'GET':
# command = 'runuser -l abaddon bash -c "pacmd list-sink-inputs"'
command = 'sudo -u abaddon bash -c "pacmd list-sink-inputs"'
# command = 'sudo -u abaddon bash <<EOF pacmd list-sink-inputs EOF'
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)
result = process.wait()
print(process.stdout.read())
_apps = []
return render_template('sound-manager.html',
title=TITLE,
apps=_apps)
return render_template('error.html',
title='Error!',
message='Must use GET request type...')
2020-06-29 02:55:58 +00:00
@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...')
2020-07-02 02:55:56 +00:00
@app.route('/send-keys', methods=['GET', 'POST'])
def sendKeys():
2020-05-28 18:07:53 +00:00
if request.method == 'POST':
try:
text = str(request.values['text']).strip()
pyautogui.typewrite(text);
# print("\nX: {} Y: {}".format(str(x), str(y)))
# pyautogui.typewrite('Hello world!\n', interval=secs_between_keys) # useful for entering text, newline is Enter
# pyautogui.press(['left', 'left', 'left', 'left']) # Press the left arrow key 4 times.
# pyautogui.keyDown('shift') # Press the Shift key down and hold it.
# pyautogui.keyUp('shift') # Let go of the Shift key.
except Exception as e:
print( repr(e) )
return render_template('error.html',
title='Error!',
message='Key is not a valid input...')
return render_template('error.html',
title='Error!',
message='Must use POST request type...')