forked from huaiwei724/robotics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
receiver.py
34 lines (27 loc) · 907 Bytes
/
receiver.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from flask import Flask, request
import pyautogui
app = Flask(__name__)
def press_key(direction):
pyautogui.press(direction)
@app.route('/', methods=['POST'])
def receive_pixel_coordinates():
data = request.json
x = data.get('x')
y = data.get('y')
if x is not None and y is not None:
if x == 'left':
# Press left button
press_key('left')
print("Left Button Pressed")
elif x == 'right':
# Press right button
press_key('right')
print("Right Button Pressed")
elif x == 'up':
# Press forward button
press_key('up')
print("Forward Button Pressed")
return "OK"
# Change the host parameter to '0.0.0.0' to allow external connections
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0', port = 5000)