'I looking for a way to read data from a text file and at the same time listen for the same data that's in another text file
import time
import sys, os
from pynput.mouse import Controller
speed = 200
fps = [time.sleep(1. / speed)]
mouse = Controller()
run = True
while run:
"opens file"
"two sets of data are being used in points"
"mouse positions x and y"
points = set()
points1 = set()
with open("mouse.txt", "r") as f:
# each line separately
for idx, line in enumerate(f):
# strip \n & strip ( and ) & split at ,
pointstring = line.strip().strip("()").split(",")
# guard against empty/non well formed lines
if pointstring and len(pointstring) == 2:
x, y = line.strip().strip("()").split(",")
mouse.position = x, y # = or (x, y)[0], (x, y)[1] same as -----> = x,y
time.sleep(1. / speed)
else:
"if for some reason is doesn't work, it'll look for whats wrong in the txt file"
print(f"Error in line {idx}: '{line}'")
text 1:
(568, 961)
(568, 958)
(568, 956)
(568, 955)
(568, 954)
(568, 953)
(568, 951)
(568, 948)
(568, 946)
(568, 944)
(568, 943)
(568, 937)
(568, 932)
(568, 931)
(568, 928)
(568, 927)
(568, 923)
(568, 921)
(568, 919)
(568, 915)
(568, 914)
(568, 911)
(568, 908)
(568, 907)
(568, 904)
(568, 899)
(568, 896)
(568, 893)
(568, 888)
(568, 885)
text 2:
(568, 911)
As soon as text 1 reaches the point at text 2, I want it to print("yes").
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
