Python PyAutoGUI Keyboard Module Game Automation
Piano Tiles Bot

Project Overview

An automation bot that plays the Piano Tiles game by detecting black tiles and clicking on them at superhuman speeds, using color detection and automated mouse controls.

Completed: 2022
Status: Completed
Platform: Crazy Games

Project Description

The Piano Tiles Bot is an automated script designed to play the popular Piano Tiles game available on Crazy Games. The bot uses screen pixel color detection to identify the black tiles as they appear and automatically clicks on them at superhuman speeds.

The bot can be triggered with a keyboard shortcut and stopped at any time, making it easy to use and demonstrate. The project showcases how computer automation can be used to achieve perfect gameplay that would be impossible for human reflexes.

Technical Implementation

The bot is implemented in Python and uses PyAutoGUI for screen analysis and mouse control, along with the keyboard module for input handling:

piano_tiles_bot.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

import pyautogui

import keyboard

target_color = (50, 71, 70)

tolerance = 50

pixel_coordinates = [(417, 555), (492, 555), (580, 555), (656, 555)]

bot_running = [False]

keyboard.on_press_key('q', lambda _: bot_running.__setitem__(0, True))

print("Press 'q' to start the bot. Press 'esc' to stop.")

while True:

if bot_running[0]:

for coordinates in pixel_coordinates:

pixel_color = pyautogui.pixel(*coordinates)

if all(abs(pixel_color[i] - target_color[i]) <= tolerance for i in range(3)):

pyautogui.click(*coordinates)

if keyboard.is_pressed('esc'):

bot_running[0] = False

print("Stopping the bot.")

break

Key Features

  • Color-based black tile detection
  • High-speed automated clicking
  • Keyboard shortcuts for starting and stopping
  • Color tolerance to handle slight variations
  • Predefined coordinates for the four piano tile lanes

Go Back