Python PyAutoGUI Keyboard Module Mouse Automation
Click on Button Automation

Project Overview

A simple yet effective automation tool that allows users to click repeatedly at specific screen coordinates using keyboard shortcuts. Perfect for repetitive clicking tasks in applications, websites, or games.

Completed: 2022
Status: Completed
Type: Mouse Automation

Project Description

The Click on Button automation tool is designed to simplify repetitive clicking tasks by allowing users to define specific screen coordinates for automated mouse clicks. When triggered using the Ctrl key, the script moves the mouse to the predefined coordinates, performs a click, and then returns to a different position.

This tool is particularly useful for scenarios requiring repeated clicking at the same position, such as in online forms, games, or applications that don't offer built-in automation options. The entire process is controlled using keyboard shortcuts, making it easy to start and stop the automation as needed.

Technical Implementation

The tool is implemented in Python using PyAutoGUI for mouse control and the keyboard module for hotkey detection:

click_button.py
Copied to clipboard!
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

import pyautogui

import keyboard

import time

def press_coordinate(x, y):

# Move the mouse to the specified coordinates

pyautogui.moveTo(x, y)

# Click the mouse at the specified coordinates

pyautogui.click()

# Set the coordinates you want to click

x_coordinate = 1740

y_coordinate = 1000

print("Press Ctrl to click the specified coordinates.")

print("Press Esc to exit the script.")

# Function to stop the script when 'Esc' is pressed

def exit_script():

print("Exiting script.")

exit()

# Hook the exit function to 'Esc' key

keyboard.add_hotkey('esc', exit_script)

# Keep running until 'Esc' is pressed

while True:

# Check for 'Ctrl' key press

if keyboard.is_pressed('ctrl'):

press_coordinate(x_coordinate, y_coordinate)

print(f"Clicked at ({x_coordinate}, {y_coordinate})")

# Wait to avoid multiple clicks in rapid succession

time.sleep(0.5)

pyautogui.moveTo(320, 670)

time.sleep(0.5)

Key Features

  • Automated clicking at predefined screen coordinates
  • Keyboard shortcuts for control (Ctrl to click, Esc to exit)
  • Mouse repositioning after each click
  • Adjustable delay between actions
  • Simple console feedback for user monitoring

Development Process

The development of this automation tool followed these steps:

  1. Identifying the need for a simple click automation solution
  2. Selecting PyAutoGUI for mouse control and keyboard for hotkey detection
  3. Implementing the basic click function with coordinate parameters
  4. Setting up keyboard shortcuts for user control
  5. Adding safety features like the exit hotkey and delay between clicks
  6. Testing with various applications and refining the timing

Challenges & Solutions

  • Challenge: Determining the exact screen coordinates for clicking
    Solution: Created a separate utility to identify and record mouse positions
  • Challenge: Preventing unintended rapid-fire clicking
    Solution: Implemented timing delays and mouse repositioning between clicks

Results & Impact

The Click on Button automation tool successfully automates repetitive clicking tasks, saving time and reducing fatigue for the user. Its simple implementation makes it accessible even to those with limited programming knowledge, while still being effective for a wide range of applications.

This project demonstrates how even simple automation scripts can significantly improve workflow efficiency and reduce the tedium of repetitive computer tasks. The tool's flexibility makes it adaptable to various scenarios from form filling to game automation.

Go Back