-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path01_get_cursor.py
More file actions
62 lines (49 loc) · 1.38 KB
/
01_get_cursor.py
File metadata and controls
62 lines (49 loc) · 1.38 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import argparse
import time
import pyautogui
import pyperclip
def print_once() -> None:
pos = pyautogui.position()
output = f"{pos.x}, {pos.y}"
print(output)
pyperclip.copy(output)
print("Copied to clipboard.")
def watch_positions(interval: float) -> None:
print("Watching cursor position. Press Ctrl+C to stop.")
try:
while True:
pos = pyautogui.position()
print(f"{pos.x}, {pos.y}")
time.sleep(interval)
except KeyboardInterrupt:
print("Stopped.")
def interactive() -> None:
print("Move your cursor to the target point.")
print("Press Enter to capture, or type q then Enter to quit.")
while True:
choice = input("> ").strip().lower()
if choice == "q":
break
print_once()
def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser(description="Get cursor position")
parser.add_argument(
"--watch",
action="store_true",
help="Continuously print cursor position",
)
parser.add_argument(
"--interval",
type=float,
default=0.2,
help="Watch interval in seconds (default: 0.2)",
)
return parser.parse_args()
def main() -> None:
args = parse_args()
if args.watch:
watch_positions(args.interval)
else:
interactive()
if __name__ == "__main__":
main()