Thanks, computer!
This commit is contained in:
commit
8583ab16f0
3
Dockerfile
Normal file
3
Dockerfile
Normal file
@ -0,0 +1,3 @@
|
||||
FROM archlinux
|
||||
RUN pacman -Sy --noconfirm xorg-server-xvfb xdotool scrot python-flask && pacman -Sc --noconfirm
|
||||
RUN mkdir -p ~/.local/share/
|
45
flaskstuff.py
Normal file
45
flaskstuff.py
Normal file
@ -0,0 +1,45 @@
|
||||
from flask import Flask, send_file
|
||||
import os
|
||||
import subprocess
|
||||
from datetime import datetime
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
# Folder to store the screenshots
|
||||
SCREENSHOT_DIR = "/tmp/screenshots"
|
||||
if not os.path.exists(SCREENSHOT_DIR):
|
||||
os.makedirs(SCREENSHOT_DIR)
|
||||
|
||||
@app.route('/')
|
||||
def index():
|
||||
return '''
|
||||
<h1>Flask Screenshot & Click App</h1>
|
||||
<p>Take a screenshot: <a href="/screenshot">/screenshot</a></p>
|
||||
<p>Click at position (x, y): <a href="/click/100/100">/click/x/y</a></p>
|
||||
'''
|
||||
|
||||
@app.route('/screenshot')
|
||||
def screenshot():
|
||||
# Generate a screenshot file name
|
||||
timestamp = datetime.now().strftime('%Y%m%d_%H%M%S')
|
||||
screenshot_path = os.path.join(SCREENSHOT_DIR, f'screenshot_{timestamp}.png')
|
||||
|
||||
# Capture the screenshot using `scrot`
|
||||
subprocess.run(['scrot', screenshot_path])
|
||||
|
||||
# Return the screenshot file as response
|
||||
return send_file(screenshot_path, mimetype='image/png')
|
||||
|
||||
@app.route('/click/<int:x>/<int:y>')
|
||||
def click(x, y):
|
||||
# Perform a click at the specified (x, y) position using `xdotool`
|
||||
subprocess.run(['xdotool', 'mousemove', str(x), str(y), 'click', '1'])
|
||||
|
||||
return f'Click performed at position ({x}, {y})'
|
||||
|
||||
@app.route('/htmlthing')
|
||||
def htmlstuff():
|
||||
return send_file('htmlthing.html', mimetype='text/html')
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(debug=True, host='0.0.0.0', port=5000)
|
73
htmlthing.html
Normal file
73
htmlthing.html
Normal file
@ -0,0 +1,73 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Flask Screenshot & Click</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
padding: 20px;
|
||||
}
|
||||
#screenshot {
|
||||
margin-top: 20px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.message {
|
||||
margin-top: 20px;
|
||||
color: green;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>Flask Screenshot & Click App</h1>
|
||||
<p><strong>Take a Screenshot:</strong></p>
|
||||
<button onclick="takeScreenshot()">Take Screenshot</button>
|
||||
<div id="screenshot-div">
|
||||
<p><strong>Click on the Image to Trigger Click at X, Y:</strong></p>
|
||||
<img id="screenshot" width='1280px' height='720px' style="display:none;" />
|
||||
</div>
|
||||
|
||||
<div class="message" id="click-message"></div>
|
||||
|
||||
<script>
|
||||
// Function to take a screenshot by calling the Flask /screenshot endpoint
|
||||
function takeScreenshot() {
|
||||
fetch('/screenshot')
|
||||
.then(response => response.blob())
|
||||
.then(imageBlob => {
|
||||
const imageUrl = URL.createObjectURL(imageBlob);
|
||||
const screenshotImage = document.getElementById('screenshot');
|
||||
screenshotImage.src = imageUrl;
|
||||
screenshotImage.style.display = 'block';
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error taking screenshot:', error);
|
||||
});
|
||||
}
|
||||
|
||||
// Function to simulate a click at the (x, y) coordinates of the image
|
||||
const clickableImage = document.getElementById('screenshot');
|
||||
clickableImage.addEventListener('click', function(event) {
|
||||
const x = event.pageX - this.offsetLeft;
|
||||
const y = event.pageY - this.offsetTop;
|
||||
|
||||
// Trigger the Flask /click/x/y endpoint using the x and y coordinates of the click
|
||||
fetch(`/click/${x}/${y}`)
|
||||
.then(response => response.text())
|
||||
.then(message => {
|
||||
document.getElementById('click-message').innerText = message;
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error triggering click:', error);
|
||||
})
|
||||
.then(() => {
|
||||
takeScreenshot();
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
Loading…
Reference in New Issue
Block a user