Python OCR PyTesseract Typing Automation
10FastFinger Bot

Project Overview

An automated typing bot specifically designed for the 10FastFinger typing test website. It captures text from the screen using OCR technology, automatically types it with configurable speed, and can achieve exceptional typing speeds with high accuracy.

Completed: 2023
Status: Completed
Type: Typing Automation

Project Description

The 10FastFinger Bot is a specialized automation tool designed to interact with the popular 10FastFinger typing test website. Using optical character recognition (OCR) technology, it captures text from the screen and automatically types it at configurable speeds.

The bot is triggered by keyboard shortcuts and can achieve impressive typing speeds while maintaining high accuracy. This project demonstrates practical applications of screen scraping, text recognition, and keyboard simulation techniques within a specific web context.

Technical Implementation

The bot is implemented in Python and leverages several key libraries for its functionality:

10ff_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 25 26 27 28 29 30 31 32 33

import pytesseract

from PIL import ImageGrab

from pynput import keyboard

import time

x = 40

y = 590

width = 880

height = 100

enter_pressed = False

def extract_text_from_screen(x, y, width, height):

screenshot = ImageGrab.grab(bbox=(x, y, x + width, y + height))

screenshot = screenshot.convert("L")

extracted_text = pytesseract.image_to_string(screenshot)

return extracted_text

def replace_enter_with_space(text):

return text.replace("\n", " ")

def type_text(text):

for char in text:

keyboard.Controller().type(char)

time.sleep(0.06) # Delay of 0.06 seconds (60ms)

def on_press(key):

global enter_pressed

if key == keyboard.Key.space:

enter_pressed = False

extracted_text = extract_text_from_screen(x, y, width, height)

modified_text = replace_enter_with_space(extracted_text)

type_text(modified_text)

elif key == keyboard.Key.enter:

enter_pressed = True

return False

def on_release(key):

pass

def listen_for_input():

with keyboard.Listener(on_press=on_press, on_release=on_release) as listener:

listener.join()

listen_for_input()

Key Features

  • Screen capture and OCR for real-time text extraction
  • Optimized for 10FastFinger's specific layout and word presentation
  • Adjustable typing speed (currently set to 60ms delay)
  • Keyboard shortcuts for easy operation (Space to start, Enter to exit)
  • Automatic text formatting to handle line breaks

Development Process

The development process involved these key steps:

  1. Analyzing the 10FastFinger website interface to identify text display areas
  2. Determining optimal screen capture coordinates for the word list
  3. Implementing OCR with PyTesseract for text extraction
  4. Creating keyboard input simulation with the pynput library
  5. Setting up keyboard listeners for bot control
  6. Testing and optimizing typing speed and accuracy

Challenges & Solutions

  • Challenge: Accurate text extraction from the 10FastFinger interface
    Solution: Identified precise screen coordinates and optimized image processing for better OCR results
  • Challenge: Finding the optimal typing speed
    Solution: Experimented with different delay values to balance between maximum scores and avoiding detection
  • Challenge: Handling text with special characters and formatting
    Solution: Implemented text cleanup functions to handle newlines and other formatting issues

Results & Impact

The 10FastFinger Bot consistently achieves impressive typing speeds, often exceeding 150 words per minute with near-perfect accuracy. This performance demonstrates the effectiveness of OCR-based automation in web interfaces.

Beyond the immediate application, this project showcases the integration of several technologies (screen capture, OCR, keyboard simulation) to create a cohesive automation solution. It serves as a practical example of how Python can be used to automate web-based tasks, even when direct API access isn't available.

Go Back