### Basic Installation from PyPI Source: https://github.com/lax3n/humantyping/blob/master/README.md Install the core humantyping library from PyPI for basic usage. ```bash pip install humantyping ``` -------------------------------- ### Install HumanTyping from Source Source: https://github.com/lax3n/humantyping/blob/master/QUICKSTART.md Development installation steps using git and either uv or pip. ```bash # Clone the repository git clone https://github.com/yourusername/HumanTyping.git cd HumanTyping # Install with uv uv sync --extra playwright # Or install with pip pip install -e .[playwright] ``` -------------------------------- ### Installation with Selenium Support from PyPI Source: https://github.com/lax3n/humantyping/blob/master/README.md Install humantyping with Selenium support directly from PyPI. ```bash pip install humantyping[selenium] ``` -------------------------------- ### Run HumanTyping Examples Source: https://github.com/lax3n/humantyping/blob/master/examples/README.md Execute different HumanTyping examples using Python scripts. ```bash python examples/simple_example.py ``` ```bash python examples/playwright_example.py ``` ```bash python examples/selenium_example.py ``` -------------------------------- ### Installation with Both Playwright and Selenium from PyPI Source: https://github.com/lax3n/humantyping/blob/master/README.md Install humantyping with support for both Playwright and Selenium from PyPI. ```bash pip install humantyping[playwright,selenium] ``` -------------------------------- ### Verify Installation Source: https://github.com/lax3n/humantyping/blob/master/README.md Run a simple Python command to confirm that the humantyping library has been installed successfully. ```python python -c "from humantyping import HumanTyper; print('✓ Installation successful!')" ``` -------------------------------- ### Install Playwright Source: https://github.com/lax3n/humantyping/blob/master/examples/README.md Install the Playwright library and its browser binaries. ```bash pip install playwright playwright install chromium ``` -------------------------------- ### Install HumanTyping with Playwright Source: https://github.com/lax3n/humantyping/blob/master/CHANGELOG.md Install the HumanTyping library with Playwright support using pip. This command installs the core library and the necessary dependencies for Playwright integration. ```bash pip install humantyping[playwright] ``` -------------------------------- ### Install from Source with uv (Development) Source: https://github.com/lax3n/humantyping/blob/master/README.md Use uv to install dependencies in editable mode for development, recommended for faster dependency management. ```bash git clone https://github.com/Lax3n/HumanTyping.git cd HumanTyping uv sync --extra playwright ``` -------------------------------- ### Install HumanTyping with Playwright Source: https://github.com/lax3n/humantyping/blob/master/examples/README.md Install the HumanTyping package with Playwright support from the root directory. ```bash pip install -e .[playwright] ``` -------------------------------- ### Install from Source (Development) Source: https://github.com/lax3n/humantyping/blob/master/README.md Clone the repository and install humantyping in editable mode for development. This allows changes to the source code to be reflected immediately. ```bash git clone https://github.com/Lax3n/HumanTyping.git cd HumanTyping pip install -e . ``` -------------------------------- ### Quick Start: Simulate Typing with Playwright Source: https://github.com/lax3n/humantyping/blob/master/CHANGELOG.md A basic example demonstrating how to use HumanTyper with Playwright to simulate typing in an asynchronous environment. It launches a browser, navigates to a page, and types text into a search box. ```python from humantyping import HumanTyper from playwright.async_api import async_playwright import asyncio async def main(): async with async_playwright() as p: browser = await p.chromium.launch(headless=False) page = await browser.new_page() await page.goto("https://google.com") typer = HumanTyper(wpm=70) search_box = page.locator("[name='q']") await search_box.click() await typer.type(search_box, "Hello!") await browser.close() asyncio.run(main()) ``` -------------------------------- ### Install Dependencies Source: https://github.com/lax3n/humantyping/blob/master/CONTRIBUTING.md Synchronize and install project dependencies using uv. This command ensures all required packages are set up. ```bash uv sync ``` -------------------------------- ### Playwright Integration Example Source: https://github.com/lax3n/humantyping/blob/master/README.md Simulates realistic typing on a webpage using Playwright and HumanTyper. Ensure Playwright is installed and browsers are available. ```python from playwright.async_api import async_playwright from humantyping import HumanTyper import asyncio async def main(): async with async_playwright() as p: browser = await p.chromium.launch(headless=False) page = await browser.new_page() await page.goto("https://google.com") typer = HumanTyper(wpm=70) # Create typer search_box = page.locator("[name='q']") await search_box.click() await typer.type(search_box, "realistic typing!") # Type like a human! await browser.close() asyncio.run(main()) ``` -------------------------------- ### Google Search Automation Example Source: https://github.com/lax3n/humantyping/blob/master/QUICKSTART.md A practical example demonstrating typing into a Google search bar and pressing Enter. ```python import asyncio from playwright.async_api import async_playwright from humantyping import HumanTyper async def google_search(): async with async_playwright() as p: browser = await p.chromium.launch(headless=False) page = await browser.new_page() await page.goto("https://google.com") typer = HumanTyper(wpm=75) # Type into Google search search_input = page.locator("[name='q']") await search_input.click() await typer.type(search_input, "How to automate with Playwright") # Press Enter await search_input.press("Enter") await page.wait_for_load_state("networkidle") print(f"Search results loaded for: {await page.title()}") await browser.close() asyncio.run(google_search()) ``` -------------------------------- ### Install from Source with Playwright (Development) Source: https://github.com/lax3n/humantyping/blob/master/README.md Clone the repository and install humantyping with Playwright support in editable mode for development. ```bash git clone https://github.com/Lax3n/HumanTyping.git cd HumanTyping pip install -e .[playwright] ``` -------------------------------- ### Install Latest Release from GitHub Source: https://github.com/lax3n/humantyping/blob/master/README.md Install the latest stable release of humantyping directly from GitHub releases using pip. ```bash pip install https://github.com/Lax3n/HumanTyping/releases/latest/download/humantyping-1.0.0-py3-none-any.whl ``` -------------------------------- ### HumanTyping Demo Output Source: https://github.com/lax3n/humantyping/blob/master/README.md Example output from running the HumanTyping demo mode via the command line, showing simulated typing time and errors. ```bash uv run main.py "The quick brown fox jumps." --mode demo ``` ```text -- Real-Time Simulation Demo: 'The quick brown fox jumps.' (Target WPM: 60.0) -- Preparing simulation... START TYPING: ---------------------------------------- The quick brown fox jumps. ---------------------------------------- Total Simulated Time: 6.2341s Errors made and corrected: 1 ``` -------------------------------- ### Basic HumanTyping Usage Source: https://github.com/lax3n/humantyping/blob/master/examples/README.md The simplest example demonstrating HumanTyping's core functionality. Requires an element to type into. ```python from humantyping import HumanTyper typer = HumanTyper(wpm=70) await typer.type(element, "Hello world!") ``` -------------------------------- ### Run Demo with Quick Test Source: https://github.com/lax3n/humantyping/blob/master/CONTRIBUTING.md Execute the main script with a quick test string in demo mode. This is useful for quick checks during development. ```bash uv run main.py "Quick test" --mode demo ``` -------------------------------- ### Run Demo Mode Source: https://github.com/lax3n/humantyping/blob/master/CONTRIBUTING.md Execute the main script in demo mode with provided text. Ensure the script is executable. ```bash uv run main.py "Test text" --mode demo ``` -------------------------------- ### Run Demo Mode Source: https://github.com/lax3n/humantyping/blob/master/README.md Execute the main script in demo mode to visualize typing simulation in real-time. Specify the text to be typed and optionally set the WPM. ```bash uv run main.py "Hello world, this is a realistic typing test." --mode demo ``` -------------------------------- ### Initialize HumanTyper Class Source: https://context7.com/lax3n/humantyping/llms.txt Configure the HumanTyper instance with specific words-per-minute (WPM) settings and keyboard layouts. ```python from humantyping import HumanTyper # Initialize with custom WPM and layout typer = HumanTyper(wpm=70, layout="qwerty") # Default: wpm=60, layout="qwerty" # Available layouts: "qwerty" (default), "azerty" azerty_typer = HumanTyper(wpm=60, layout="azerty") # Properties print(typer.wpm) # Output: 70 print(typer.layout) # Output: "qwerty" ``` -------------------------------- ### Initialize and Run MarkovTyper Simulation Source: https://context7.com/lax3n/humantyping/llms.txt Create a MarkovTyper instance for a target text and run a complete typing simulation. Useful for analyzing typing patterns and obtaining total time and event history. ```python from humantyping import MarkovTyper # Create typer for specific text typer = MarkovTyper( target_text="Hello, world!", target_wpm=70.0, # Target words per minute layout="qwerty" # Keyboard layout ) # Run complete simulation total_time, history = typer.run() print(f"Total typing time: {total_time:.2f}s") print(f"Number of events: {len(history)}") # History format: list of (timestamp, action, current_text) for timestamp, action, text in history[:10]: print(f"[{timestamp:.3f}s] {action:20} -> '{text}'") ``` -------------------------------- ### Configure Keyboard Layouts Source: https://github.com/lax3n/humantyping/blob/master/QUICKSTART.md Sets the keyboard layout to either AZERTY or QWERTY. ```python # AZERTY keyboard azerty_typer = HumanTyper(wpm=60, layout="azerty") # QWERTY keyboard (default) qwerty_typer = HumanTyper(wpm=60, layout="qwerty") ``` -------------------------------- ### CLI Usage for Demo and Monte Carlo Modes Source: https://context7.com/lax3n/humantyping/llms.txt Interact with the HumanTyping library via the command-line interface. Use `--mode demo` for real-time visualization or `--mode montecarlo` for statistical analysis, with options to customize text, WPM, and simulation count. ```bash # Basic demo mode - watch typing in real-time python main.py "Hello world, this is a realistic typing test." --mode demo # Set custom WPM python main.py "Fast typing example" --mode demo --wpm 90 # Monte Carlo mode - run statistical analysis python main.py "Performance test" --mode montecarlo --n 1000 --wpm 80 # Using uv uv run main.py "Test text" --mode demo --wpm 70 # CLI Arguments: # text The text to simulate (optional, has default) # --mode demo | montecarlo (default: demo) # --wpm Target WPM speed (default: 60) # --n Number of Monte Carlo simulations (default: 100) ``` -------------------------------- ### demo_single_run() - Real-Time Visualization Source: https://context7.com/lax3n/humantyping/llms.txt The `demo_single_run()` function provides a real-time visualization of a typing simulation directly in the terminal. ```APIDOC ## demo_single_run() - Real-Time Visualization ### Description The `demo_single_run()` function displays a real-time typing simulation in the terminal, showing characters appearing with realistic timing, errors being made, and corrections happening live. ### Method `demo_single_run(target_text, wpm)` ### Parameters - **target_text** (string) - Required - The text to simulate. - **wpm** (int) - Required - Target words per minute for the simulation. ### Request Example ```python from humantyping.simulation import demo_single_run # Run visual demo demo_single_run( target_text="The quick brown fox jumps over the lazy dog.", wpm=65 ) ``` ### Response This function does not return a value but displays a real-time animation in the terminal. ### Response Example ``` --- Real-Time Simulation Demo: 'The quick...' (Target WPM: 65) --- Preparing simulation... START TYPING: ---------------------------------------- The quick brown fox jumps over the lazy dog. ---------------------------------------- Total Simulated Time: 8.4521s Errors made and corrected: 2 ``` ``` -------------------------------- ### Configure Typing Parameters Source: https://context7.com/lax3n/humantyping/llms.txt Import and inspect tunable parameters for typing speed, error probabilities, and fatigue modeling. ```python from humantyping.config import ( # Speed settings DEFAULT_WPM, # 60 - Default typing speed WPM_STD, # 10 - WPM variance between sessions AVG_WORD_LENGTH, # 5 - Characters per word # Error probabilities PROB_ERROR, # 0.04 - 4% chance of wrong key PROB_SWAP_ERROR, # 0.015 - 1.5% chance of swap (teh -> the) PROB_NOTICE_ERROR, # 0.85 - 85% immediate error detection # Speed modifiers (< 1.0 = faster) SPEED_BOOST_COMMON_WORD, # 0.6 - Common words 40% faster SPEED_PENALTY_COMPLEX_WORD, # 1.3 - Complex words 30% slower SPEED_BOOST_BIGRAM, # 0.4 - Common bigrams 60% faster # Timing (seconds) TIME_SPACE_PAUSE_MEAN, # 0.25 - Pause between words TIME_BACKSPACE_MEAN, # 0.12 - Backspace key time TIME_REACTION_MEAN, # 0.35 - "Oops" reaction delay TIME_UPPERCASE_PENALTY, # 0.2 - Shift key overhead # Fatigue modeling FATIGUE_FACTOR, # 1.0005 - 0.05% slowdown per char FATIGUE_CAP, # 1.5 - Maximum fatigue multiplier ) # Example: Understanding timing calculation base_keystroke = 60 / (DEFAULT_WPM * AVG_WORD_LENGTH) # ~0.2s per keystroke print(f"Base keystroke time at {DEFAULT_WPM} WPM: {base_keystroke:.3f}s") ``` -------------------------------- ### MarkovTyper.step() - Single Step Execution Source: https://context7.com/lax3n/humantyping/llms.txt The `step()` method allows for executing the typing simulation one event at a time, providing fine-grained control and enabling real-time playback. ```APIDOC ## MarkovTyper.step() - Single Step Execution ### Description The `step()` method advances the simulation by one event (keystroke, error, or backspace). Returns `None` when typing is complete. Use this for fine-grained control or real-time playback. ### Method `step()` ### Parameters None ### Request Example ```python from humantyping import MarkovTyper typer = MarkovTyper("Test", target_wpm=60) # Execute step by step while True: event = typer.step() if event is None: break timestamp, action, current_text = event if "ERROR" in action: print(f"Oops! Made an error at {timestamp:.2f}s") elif "BACKSPACE" in action: print(f"Correcting... text is now: '{current_text}'") elif "SWAP" in action: print(f"Swap error (like 'teh' -> 'the')") else: print(f"Typed: '{current_text}'") # Access final state print(f"Final text: '{typer.state.current_text}'") print(f"Total time: {typer.state.total_time:.2f}s") print(f"Fatigue factor: {typer.state.fatigue_multiplier:.3f}") ``` ### Response - **event** (tuple or None) - A tuple containing (timestamp, action, current_text) for the current event, or `None` if typing is complete. ### Response Example ``` Oops! Made an error at 0.52s Correcting... text is now: 'T' Typed: 'Te' Typed: 'Tes' Typed: 'Test' Final text: 'Test' Total time: 1.25s Fatigue factor: 1.015 ``` ``` -------------------------------- ### Basic HumanTyping Usage with Playwright Source: https://github.com/lax3n/humantyping/blob/master/QUICKSTART.md Demonstrates initializing the HumanTyper and typing into a search input field. ```python import asyncio from playwright.async_api import async_playwright from humantyping import HumanTyper async def main(): async with async_playwright() as p: browser = await p.chromium.launch(headless=False) page = await browser.new_page() await page.goto("https://example.com") # Create a human typer (default: 60 WPM) typer = HumanTyper() # Or customize the typing speed fast_typer = HumanTyper(wpm=90) # Type into any input field search_box = page.locator("input[name='search']") await search_box.click() await typer.type(search_box, "Hello, realistic typing!") await browser.close() asyncio.run(main()) ``` -------------------------------- ### Execute MarkovTyper Simulation Step-by-Step Source: https://context7.com/lax3n/humantyping/llms.txt Advance the typing simulation one event at a time using the `step()` method. This is useful for fine-grained control, real-time playback, or debugging. The loop continues until `step()` returns `None`, indicating completion. ```python from humantyping import MarkovTyper typer = MarkovTyper("Test", target_wpm=60) # Execute step by step while True: event = typer.step() if event is None: break timestamp, action, current_text = event if "ERROR" in action: print(f"Oops! Made an error at {timestamp:.2f}s") elif "BACKSPACE" in action: print(f"Correcting... text is now: '{current_text}'") elif "SWAP" in action: print(f"Swap error (like 'teh' -> 'the')") else: print(f"Typed: '{current_text}'") # Access final state print(f"Final text: '{typer.state.current_text}'") print(f"Total time: {typer.state.total_time:.2f}s") print(f"Fatigue factor: {typer.state.fatigue_multiplier:.3f}") ``` -------------------------------- ### Run Real-Time Typing Simulation Demo Source: https://context7.com/lax3n/humantyping/llms.txt Visualize a single typing simulation in the terminal using `demo_single_run()`. This function displays characters appearing with realistic timing, including errors and corrections, providing a live typing experience. ```python from humantyping.simulation import demo_single_run # Run visual demo demo_single_run( target_text="The quick brown fox jumps over the lazy dog.", wpm=65 ) ``` -------------------------------- ### Customize Library Configuration Source: https://github.com/lax3n/humantyping/blob/master/QUICKSTART.md Global settings for typing behavior, including error probabilities and speed boosts. ```python DEFAULT_WPM = 60 # Base typing speed PROB_ERROR = 0.04 # 4% chance of typing errors PROB_SWAP_ERROR = 0.015 # 1.5% swap errors SPEED_BOOST_COMMON_WORD = 0.6 # 40% faster for common words ``` -------------------------------- ### HumanTyping Project Structure Source: https://github.com/lax3n/humantyping/blob/master/README.md Overview of the HumanTyping library's project structure, highlighting key modules like config.py, typer.py, and integration.py. ```text HumanTyping/ ├── src/ │ ├── config.py # All simulation parameters │ ├── typer.py # Core Markov model and state machine │ ├── keyboard.py # QWERTY/AZERTY layouts, key distances │ ├── language.py # Word difficulty, common bigrams │ ├── simulation.py # Demo and Monte Carlo runners │ └── integration.py # Playwright/Selenium integration ├── main.py # CLI entry point └── README.md ``` -------------------------------- ### HumanTyper Class Initialization Source: https://github.com/lax3n/humantyping/blob/master/QUICKSTART.md Initializes the HumanTyper instance with configurable typing speed and keyboard layout. ```APIDOC ## HumanTyper(wpm=60, layout="qwerty") ### Description Initializes the main class for realistic typing simulation. ### Parameters - **wpm** (float) - Optional - Target words per minute (default: 60) - **layout** (str) - Optional - Keyboard layout, either "qwerty" or "azerty" (default: "qwerty") ``` -------------------------------- ### Clone Repository Source: https://github.com/lax3n/humantyping/blob/master/CONTRIBUTING.md Clone your forked repository to your local machine. Replace YOUR_USERNAME with your GitHub username. ```bash git clone https://github.com/YOUR_USERNAME/HumanTyping.git ``` -------------------------------- ### HumanTyping Configuration Parameters Source: https://github.com/lax3n/humantyping/blob/master/README.md Customize typing simulation by editing src/config.py. Adjust typing speed, error rates, speed boosts, timing, and fatigue factors. ```python # Typing speed DEFAULT_WPM = 60 # Base speed WPM_STD = 10 # Variance between sessions # Error rates PROB_ERROR = 0.04 # 4% chance of typing wrong key PROB_SWAP_ERROR = 0.015 # 1.5% chance of swapping two characters PROB_NOTICE_ERROR = 0.85 # 85% chance to notice errors immediately # Speed adjustments SPEED_BOOST_COMMON_WORD = 0.6 # Common words 40% faster SPEED_BOOST_BIGRAM = 0.4 # Frequent bigrams 60% faster SPEED_PENALTY_COMPLEX_WORD = 1.3 # Complex words 30% slower # Timing (seconds) TIME_SPACE_PAUSE_MEAN = 0.25 # Pause between words TIME_BACKSPACE_MEAN = 0.12 # Backspace press time TIME_ARROW_MEAN = 0.15 # Arrow key navigation time TIME_REACTION_MEAN = 0.35 # "Oops" delay after error # Fatigue FATIGUE_FACTOR = 1.0005 # 0.05% slowdown per character ``` -------------------------------- ### Realistic Typing with Playwright (Async) Source: https://github.com/lax3n/humantyping/blob/master/README.md Integrate realistic typing into Playwright scripts. Import HumanTyper, create an instance with desired WPM, and use the type method with a locator. ```python import asyncio from playwright.async_api import async_playwright from humantyping import HumanTyper # Import from the package! async def main(): async with async_playwright() as p: browser = await p.chromium.launch(headless=False) page = await browser.new_page() await page.goto("https://example.com") # Create typer with custom WPM typer = HumanTyper(wpm=70) # Type realistically into any input field search_box = page.locator("input[name='search']") await search_box.click() await typer.type(search_box, "How to type like a human?") await browser.close() if __name__ == "__main__": asyncio.run(main()) ``` -------------------------------- ### Configure HumanTyping Speed (WPM) Source: https://github.com/lax3n/humantyping/blob/master/examples/README.md Customize the typing speed by adjusting the WPM parameter when initializing HumanTyper. ```python # Slow typer slow_typer = HumanTyper(wpm=40) # Average typer (default) normal_typer = HumanTyper(wpm=60) # Fast typer fast_typer = HumanTyper(wpm=90) # Pro typer pro_typer = HumanTyper(wpm=120) ``` -------------------------------- ### Run Monte Carlo Mode Source: https://github.com/lax3n/humantyping/blob/master/README.md Execute the main script in Monte Carlo mode to generate statistical analysis over multiple simulations. Specify the text, number of simulations, and target WPM. ```bash uv run main.py "Performance test" --mode montecarlo --n 1000 --wpm 80 ``` -------------------------------- ### Simulate Human Typing with Playwright Source: https://context7.com/lax3n/humantyping/llms.txt Demonstrates using HumanTyper with different WPM settings to fill form fields in a Playwright automation script. ```python import asyncio from playwright.async_api import async_playwright from humantyping import HumanTyper async def fill_form(): async with async_playwright() as p: browser = await p.chromium.launch(headless=False) page = await browser.new_page() await page.goto("https://example.com/signup") # Different typers for different user behaviors careful_typer = HumanTyper(wpm=45) # Slow, careful typing normal_typer = HumanTyper(wpm=70) # Average user fast_typer = HumanTyper(wpm=100) # Expert typist # Fill form fields with appropriate speeds username = page.locator("#username") await username.click() await careful_typer.type(username, "john_doe_2024") # Careful with username email = page.locator("#email") await email.click() await normal_typer.type(email, "john.doe@example.com") # Long text with fatigue simulation bio = page.locator("#bio") await bio.click() await normal_typer.type(bio, "I am a software developer with 10 years of experience. " "I enjoy building automation tools and making software more human-like." ) # Speed decreases naturally over this long text await browser.close() asyncio.run(fill_form()) ``` -------------------------------- ### CLI Interface Source: https://context7.com/lax3n/humantyping/llms.txt The command-line interface (CLI) allows users to run typing simulations and Monte Carlo analyses directly from the terminal without writing Python code. ```APIDOC ## CLI Interface ### Description The command-line interface provides quick access to demo and Monte Carlo modes without writing code. Run directly with Python or uv. ### Usage ```bash # Basic demo mode - watch typing in real-time python main.py "Hello world, this is a realistic typing test." --mode demo # Set custom WPM python main.py "Fast typing example" --mode demo --wpm 90 # Monte Carlo mode - run statistical analysis python main.py "Performance test" --mode montecarlo --n 1000 --wpm 80 # Using uv uv run main.py "Test text" --mode demo --wpm 70 ``` ### CLI Arguments - **text** (string) - The text to simulate (optional, has default). - **--mode** (string) - `demo` | `montecarlo` (default: `demo`). - **--wpm** (int) - Target WPM speed (default: 60). - **--n** (int) - Number of Monte Carlo simulations (default: 100). ``` -------------------------------- ### run_monte_carlo() - Statistical Analysis Source: https://context7.com/lax3n/humantyping/llms.txt The `run_monte_carlo()` function performs multiple typing simulations to estimate the distribution of typing times, useful for benchmarking and performance analysis. ```APIDOC ## run_monte_carlo() - Statistical Analysis ### Description The `run_monte_carlo()` function runs multiple typing simulations to estimate the distribution of typing times. Useful for benchmarking, testing performance characteristics, and understanding variance in typing behavior. ### Method `run_monte_carlo(target_text, wpm, n_simulations)` ### Parameters - **target_text** (string) - Required - The text to simulate. - **wpm** (int) - Required - Target words per minute for the simulations. - **n_simulations** (int) - Required - The number of simulations to run. ### Request Example ```python from humantyping.simulation import run_monte_carlo # Run 1000 simulations for statistical analysis times = run_monte_carlo( target_text="Performance testing text sample", wpm=80, n_simulations=1000 ) # The function returns numpy array of times for further analysis import numpy as np print(f"Median time: {np.median(times):.4f}s") print(f"95th percentile: {np.percentile(times, 95):.4f}s") ``` ### Response - **times** (numpy.ndarray) - A NumPy array containing the total typing time for each simulation. ### Response Example ``` Estimated Mean Time : 3.2145 s Standard Deviation : 0.4521 s Min / Max : 2.1034 s / 5.8912 s Computation Time : 2.1456 s Median time: 3.1500s 95th percentile: 4.0500s ``` ``` -------------------------------- ### Model Keyboard Geometry Source: https://context7.com/lax3n/humantyping/llms.txt Use the KeyboardLayout class to calculate key distances and identify neighbors for realistic error generation. ```python from humantyping.keyboard import KeyboardLayout # Create layout instances qwerty = KeyboardLayout("qwerty") azerty = KeyboardLayout("azerty") # Get neighboring keys (for error simulation) neighbors = qwerty.get_neighbor_keys("f") print(f"Neighbors of 'f': {neighbors}") # ['r', 't', 'd', 'g', 'c', 'v'] # Calculate key distance distance = qwerty.get_distance("a", "l") print(f"Distance a->l: {distance:.2f}") # ~8.0 (far keys) distance = qwerty.get_distance("f", "g") print(f"Distance f->g: {distance:.2f}") # 1.0 (adjacent keys) # Get random neighbor (for generating typos) wrong_key = qwerty.get_random_neighbor("t") print(f"Random neighbor of 't': {wrong_key}") # Might be 'r', 'y', 'g', etc. # Check for accented characters print(qwerty.is_composed_accent("é")) # True (requires compose on QWERTY) print(azerty.is_direct_accent("é")) # True (direct key on AZERTY) # Check if character exists on keyboard print(qwerty.has_key("a")) # True print(qwerty.has_key("€")) # False ``` -------------------------------- ### Typing with Selenium & Appium (Sync) Source: https://github.com/lax3n/humantyping/blob/master/README.md Use HumanTyper for synchronous typing simulation with Selenium or Appium. Instantiate HumanTyper and call type_sync with the element and text. ```python from selenium import webdriver from humantyping import HumanTyper # For Selenium driver = webdriver.Chrome() driver.get("https://example.com") human = HumanTyper(wpm=60) search_box = driver.find_element("name", "search") human.type_sync(search_box, "Typing with human-like behavior") driver.quit() # For Appium # from appium import webdriver # ... driver setup ... # search_field = driver.find_element(by=AppiumBy.ACCESSIBILITY_ID, value='Search') # human.type_sync(search_field, "Typing on mobile") ``` -------------------------------- ### Integrate with Appium Source: https://context7.com/lax3n/humantyping/llms.txt Use the type_appium() method to perform human-like typing on mobile elements via Appium drivers. ```python from appium import webdriver as appium_webdriver from appium.webdriver.common.appiumby import AppiumBy from humantyping import HumanTyper # Setup Appium driver (example capabilities) caps = { "platformName": "Android", "deviceName": "emulator-5554", "app": "/path/to/app.apk" } driver = appium_webdriver.Remote("http://localhost:4723/wd/hub", caps) # Create typer for mobile (slower for touch keyboards) typer = HumanTyper(wpm=45) # Find and focus the input element search_field = driver.find_element(AppiumBy.ACCESSIBILITY_ID, "Search") search_field.click() # Ensure element is focused # Type with human-like behavior on mobile typer.type_appium(driver, "Hello Appium mobile typing") driver.quit() ``` -------------------------------- ### MarkovTyper - Core Simulation Engine Source: https://context7.com/lax3n/humantyping/llms.txt The MarkovTyper class provides a core simulation engine for typing. It allows for fine-grained control over the simulation process and analysis of typing patterns. ```APIDOC ## MarkovTyper - Core Simulation Engine ### Description The `MarkovTyper` class implements the semi-Markov process for typing simulation. It maintains typing state including current text, history of actions, fatigue multiplier, and mental cursor position. Use this class directly when you need fine-grained control over the simulation or want to analyze typing patterns. ### Method `MarkovTyper(target_text, target_wpm, layout)` ### Parameters - **target_text** (string) - Required - The text to be typed. - **target_wpm** (float) - Required - The target words per minute. - **layout** (string) - Optional - The keyboard layout (e.g., "qwerty"). ### Request Example ```python from humantyping import MarkovTyper # Create typer for specific text typer = MarkovTyper( target_text="Hello, world!", target_wpm=70.0, # Target words per minute layout="qwerty" # Keyboard layout ) # Run complete simulation total_time, history = typer.run() print(f"Total typing time: {total_time:.2f}s") print(f"Number of events: {len(history)}") # History format: list of (timestamp, action, current_text) for timestamp, action, text in history[:10]: print(f"[{timestamp:.3f}s] {action:20} -> '{text}'") ``` ### Response - **total_time** (float) - The total time taken for the simulation in seconds. - **history** (list) - A list of tuples, where each tuple contains (timestamp, action, current_text). ### Response Example ``` Total typing time: 1.72s Number of events: 15 [0.000s] INIT (WPM: 72.3) -> '' [0.152s] TYPED 'H' -> 'H' [0.298s] TYPED 'e' -> 'He' [0.401s] TYPED 'l' -> 'Hel' [0.489s] TYPED 'l' -> 'Hell' [0.612s] TYPED 'o' -> 'Hello' [0.891s] TYPED ',' -> 'Hello,' [1.203s] TYPED ' ' -> 'Hello, ' [1.356s] TYPED_ERROR 'e' -> 'Hello, e' (error!) [1.712s] BACKSPACE -> 'Hello, ' (correction) ``` ``` -------------------------------- ### Troubleshoot Element Focus Source: https://github.com/lax3n/humantyping/blob/master/QUICKSTART.md Ensures the element is focused before typing to avoid errors. ```python element = page.locator("input#field") await element.click() # Important! await typer.type(element, "text") ``` -------------------------------- ### Run Monte Carlo Simulations for Statistical Analysis Source: https://context7.com/lax3n/humantyping/llms.txt Execute multiple typing simulations using `run_monte_carlo()` to estimate the distribution of typing times. This function returns a NumPy array of times, useful for calculating statistics like median and percentiles. ```python from humantyping.simulation import run_monte_carlo # Run 1000 simulations for statistical analysis times = run_monte_carlo( target_text="Performance testing text sample", wpm=80, n_simulations=1000 ) # The function returns numpy array of times for further analysis import numpy as np print(f"Median time: {np.median(times):.4f}s") print(f"95th percentile: {np.percentile(times, 95):.4f}s") ``` -------------------------------- ### Run Playwright Integration Test Source: https://github.com/lax3n/humantyping/blob/master/CONTRIBUTING.md Execute the integration tests using Playwright. This command is used to verify end-to-end functionality. ```bash uv run test_integration.py ``` -------------------------------- ### HumanTyper - Main Integration Class Source: https://context7.com/lax3n/humantyping/llms.txt The HumanTyper class is the primary interface for integrating realistic typing into automation frameworks. It wraps the underlying Markov model and provides simple async and sync methods for Playwright, Selenium, and Appium integration. The class accepts a target WPM (words per minute) and keyboard layout, then handles all typing events including correct keystrokes, errors, swap errors, backspace corrections, and timing delays automatically. ```APIDOC ## HumanTyper - Main Integration Class ### Description The `HumanTyper` class is the primary interface for integrating realistic typing into automation frameworks. It wraps the underlying Markov model and provides simple async and sync methods for Playwright, Selenium, and Appium integration. The class accepts a target WPM (words per minute) and keyboard layout, then handles all typing events including correct keystrokes, errors, swap errors, backspace corrections, and timing delays automatically. ### Initialization ```python from humantyping import HumanTyper # Initialize with custom WPM and layout typer = HumanTyper(wpm=70, layout="qwerty") # Default: wpm=60, layout="qwerty" # Available layouts: "qwerty" (default), "azerty" azerty_typer = HumanTyper(wpm=60, layout="azerty") ``` ### Properties - **wpm** (int) - The words per minute setting for typing speed. - **layout** (str) - The keyboard layout being used (e.g., "qwerty", "azerty"). ### Property Examples ```python print(typer.wpm) # Output: 70 print(typer.layout) # Output: "qwerty" ``` ``` -------------------------------- ### Integrate with Selenium Source: https://context7.com/lax3n/humantyping/llms.txt Use the type_sync() method for synchronous typing operations in standard Selenium workflows. ```python from selenium import webdriver from selenium.webdriver.common.by import By from humantyping import HumanTyper # Setup Selenium WebDriver driver = webdriver.Chrome() driver.get("https://google.com") # Create typer typer = HumanTyper(wpm=65) # Find element and type search_box = driver.find_element(By.NAME, "q") search_box.click() # Type with human-like behavior (synchronous) typer.type_sync(search_box, "Selenium automation typing") # Automatically handles: keystrokes, backspace corrections, timing driver.quit() ``` -------------------------------- ### Integrate with Playwright Source: https://context7.com/lax3n/humantyping/llms.txt Use the async type() method to simulate human typing within Playwright automation workflows. ```python import asyncio from playwright.async_api import async_playwright from humantyping import HumanTyper async def main(): async with async_playwright() as p: browser = await p.chromium.launch(headless=False) page = await browser.new_page() await page.goto("https://google.com") # Create typer with desired speed typer = HumanTyper(wpm=70) # Locate input element search_box = page.locator("[name='q']") await search_box.click() # Type with realistic human behavior await typer.type(search_box, "How to type like a human?") # Simulates: variable speed, typos, corrections, fatigue await browser.close() asyncio.run(main()) ``` -------------------------------- ### HumanTyper.type() - Async Playwright Integration Source: https://context7.com/lax3n/humantyping/llms.txt The `type()` method is the main async method for Playwright integration. It simulates realistic human typing into any Playwright Locator or ElementHandle, including variable speed, errors, and corrections. The method automatically handles timing delays between keystrokes. ```APIDOC ## HumanTyper.type() - Async Playwright Integration ### Description The `type()` method is the main async method for Playwright integration. It simulates realistic human typing into any Playwright Locator or ElementHandle, including variable speed, errors, and corrections. The method automatically handles timing delays between keystrokes. ### Method `async typer.type(locator: Locator | ElementHandle, text: str)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **locator** (Locator | ElementHandle) - The Playwright locator or element handle to type into. - **text** (str) - The text to be typed. ### Request Example ```python import asyncio from playwright.async_api import async_playwright from humantyping import HumanTyper async def main(): async with async_playwright() as p: browser = await p.chromium.launch(headless=False) page = await browser.new_page() await page.goto("https://google.com") # Create typer with desired speed typer = HumanTyper(wpm=70) # Locate input element search_box = page.locator("[name='q']") await search_box.click() # Type with realistic human behavior await typer.type(search_box, "How to type like a human?") # Simulates: variable speed, typos, corrections, fatigue await browser.close() asyncio.run(main()) ``` ### Response None (This method performs an action, it does not return a value directly related to the typing operation itself.) #### Success Response (200) N/A #### Response Example N/A ``` -------------------------------- ### Configure Typing Speed Source: https://github.com/lax3n/humantyping/blob/master/QUICKSTART.md Adjusts the words per minute (WPM) for the HumanTyper instance. ```python # Slow typer (40 WPM) slow_typer = HumanTyper(wpm=40) # Fast typer (100 WPM) fast_typer = HumanTyper(wpm=100) ``` -------------------------------- ### Analyze Language Difficulty Source: https://context7.com/lax3n/humantyping/llms.txt Perform word difficulty analysis and detect common bigrams to influence typing speed simulation. ```python from humantyping.language import get_word_difficulty, is_common_bigram, COMMON_WORDS # Word difficulty affects typing speed print(get_word_difficulty("the")) # "common" - typed 40% faster print(get_word_difficulty("hello")) # "normal" - base speed print(get_word_difficulty("extraordinary")) # "complex" - typed 30% slower print(get_word_difficulty("jazz")) # "complex" - contains 'z', 'j' # Bigram detection for burst typing print(is_common_bigram("t", "h")) # True - "th" is common print(is_common_bigram("e", "r")) # True - "er" is common print(is_common_bigram("q", "z")) # False - uncommon pair # Common words set print("the" in COMMON_WORDS) # True print(len(COMMON_WORDS)) # 100 most common English words ``` -------------------------------- ### HumanTyper.type_sync() - Selenium Integration Source: https://context7.com/lax3n/humantyping/llms.txt The `type_sync()` method provides synchronous typing for Selenium WebElements. It uses `time.sleep()` for delays and Selenium's `send_keys()` for input, making it compatible with standard Selenium workflows. ```APIDOC ## HumanTyper.type_sync() - Selenium Integration ### Description The `type_sync()` method provides synchronous typing for Selenium WebElements. It uses `time.sleep()` for delays and Selenium's `send_keys()` for input, making it compatible with standard Selenium workflows. ### Method `typer.type_sync(element: WebElement, text: str)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **element** (WebElement) - The Selenium WebElement to type into. - **text** (str) - The text to be typed. ### Request Example ```python from selenium import webdriver from selenium.webdriver.common.by import By from humantyping import HumanTyper # Setup Selenium WebDriver driver = webdriver.Chrome() driver.get("https://google.com") # Create typer typer = HumanTyper(wpm=65) # Find element and type search_box = driver.find_element(By.NAME, "q") search_box.click() # Type with human-like behavior (synchronous) typer.type_sync(search_box, "Selenium automation typing") # Automatically handles: keystrokes, backspace corrections, timing driver.quit() ``` ### Response None (This method performs an action, it does not return a value directly related to the typing operation itself.) #### Success Response (200) N/A #### Response Example N/A ``` -------------------------------- ### HumanTyper.type_appium() - Mobile Appium Integration Source: https://context7.com/lax3n/humantyping/llms.txt The `type_appium()` method uses W3C Actions to type into focused mobile elements via Appium. It requires the target element to be focused before calling, then types using ActionChains at the driver level. ```APIDOC ## HumanTyper.type_appium() - Mobile Appium Integration ### Description The `type_appium()` method uses W3C Actions to type into focused mobile elements via Appium. It requires the target element to be focused before calling, then types using ActionChains at the driver level. ### Method `typer.type_appium(driver: RemoteWebDriver, text: str)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **driver** (RemoteWebDriver) - The Appium WebDriver instance. - **text** (str) - The text to be typed. ### Request Example ```python from appium import webdriver as appium_webdriver from appium.webdriver.common.appiumby import AppiumBy from humantyping import HumanTyper # Setup Appium driver (example capabilities) caps = { "platformName": "Android", "deviceName": "emulator-5554", "app": "/path/to/app.apk" } driver = appium_webdriver.Remote("http://localhost:4723/wd/hub", caps) # Create typer for mobile (slower for touch keyboards) typer = HumanTyper(wpm=45) # Find and focus the input element search_field = driver.find_element(AppiumBy.ACCESSIBILITY_ID, "Search") search_field.click() # Ensure element is focused # Type with human-like behavior on mobile typer.type_appium(driver, "Hello Appium mobile typing") driver.quit() ``` ### Response None (This method performs an action, it does not return a value directly related to the typing operation itself.) #### Success Response (200) N/A #### Response Example N/A ``` -------------------------------- ### Troubleshoot Typing Speed Source: https://github.com/lax3n/humantyping/blob/master/QUICKSTART.md Adjusts WPM to resolve issues with typing being too slow or too fast. ```python # Slower typer = HumanTyper(wpm=30) # Faster typer = HumanTyper(wpm=120) ``` -------------------------------- ### async type(page_element, text) Source: https://github.com/lax3n/humantyping/blob/master/QUICKSTART.md Types the provided text into a specified Playwright element using human-like behavior. ```APIDOC ## async type(page_element, text) ### Description Types text into a Playwright element with human-like behavior including variable speed, errors, and corrections. ### Parameters - **page_element** (Locator/ElementHandle) - Required - The Playwright element to type into. - **text** (str) - Required - The string content to type. ### Request Example ```python typer = HumanTyper(wpm=70) await typer.type(page.locator("#username"), "john_doe") ``` ``` -------------------------------- ### Type Text into Element Source: https://github.com/lax3n/humantyping/blob/master/QUICKSTART.md Basic usage of the type method on a specific Playwright locator. ```python typer = HumanTyper(wpm=70) await typer.type(page.locator("#username"), "john_doe") ``` -------------------------------- ### Adjust Typing Speed Source: https://github.com/lax3n/humantyping/blob/master/examples/README.md Modify the WPM value in the code to control the typing speed. ```python typer = HumanTyper(wpm=80) # Change this value ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.