Created
June 28, 2025 05:18
-
-
Save 1kko/d798c69ce076b8268442882f570f3632 to your computer and use it in GitHub Desktop.
loop click and key press using python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pyautogui | |
import time | |
def get_click_position(): | |
print("Move your mouse to the position you want to click and press Enter...") | |
input() | |
x, y = pyautogui.position() | |
print(f"Click position set to: ({x}, {y})") | |
return x, y | |
def main(): | |
# Safety settings | |
pyautogui.FAILSAFE = True # Move mouse to corner to abort | |
pyautogui.PAUSE = 0.1 # Small pause between actions | |
# Get the position to click | |
click_x, click_y = get_click_position() | |
print("\nStarting automation sequence...") | |
print("Press 'q' to quit") | |
try: | |
while True: | |
# Simulate pressing 'D' key 5 times | |
# Move to position and click | |
pyautogui.moveTo(click_x, click_y, duration=0.2) | |
pyautogui.click() | |
print("Clicked at specified position") | |
time.sleep(3) | |
for i in range(5): | |
pyautogui.press('d') | |
print(f"Pressed 'D' key: {i+1}/5") | |
time.sleep(0.2) # Small delay between presses | |
# Wait 5 seconds before next sequence | |
print("Waiting 5 seconds before next sequence...") | |
time.sleep(3) | |
except Exception as e: | |
print(f"\nError occurred: {e}") | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment