45 lines
1.6 KiB
Plaintext
45 lines
1.6 KiB
Plaintext
import subprocess
|
|
import sys
|
|
|
|
# Function to execute a command using ydotool
|
|
def execute_ydotool_command(command):
|
|
try:
|
|
subprocess.run(command, check=True)
|
|
except subprocess.CalledProcessError as e:
|
|
print(f"Error executing {' '.join(command)}: {e}", file=sys.stderr)
|
|
|
|
# Function to simulate mouse click
|
|
def ydotool_click(x, y, button='left', repeat=1):
|
|
# Move the mouse to the specified coordinates
|
|
execute_ydotool_command(['ydotool', 'mousemove', str(x), str(y)])
|
|
button_arg = '1' if button == 'left' else '2'
|
|
for _ in range(repeat):
|
|
execute_ydotool_command(['ydotool', 'click', button_arg])
|
|
|
|
def main():
|
|
coordinates = []
|
|
click_type = 'left'
|
|
repeat = 1
|
|
|
|
num_coordinates = int(input("Enter the number of coordinates to record: "))
|
|
|
|
for i in range(num_coordinates):
|
|
while True:
|
|
coords = input(f"Enter coordinates {i+1} (format x,y): ")
|
|
try:
|
|
x, y = map(int, coords.split(','))
|
|
coordinates.append((x, y))
|
|
break # Exit the loop if coordinates are valid
|
|
except ValueError:
|
|
print("Invalid format. Please enter coordinates in the format x,y.")
|
|
|
|
click_type = input("Enter click type (left or right, default left): ") or click_type
|
|
repeat = int(input("How many times to repeat each click (default 1): ") or repeat)
|
|
|
|
for x, y in coordinates:
|
|
ydotool_click(x, y, button=click_type, repeat=repeat)
|
|
print(f"Clicked at {x},{y} with {click_type} button, repeated {repeat} times.")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|