[Python] How to simulate faster human-like typing with Python (like pyautogui) without being...

Discussão em 'Python' iniciado por Stack, Agosto 9, 2025.

  1. Stack

    Stack Membro Participativo

    I’m working on an experiment where my professor is creating an anti-cheat website that detects typing patterns.

    In my setup, I send a request from the browser using an extension when I press a command (Ctrl + Alt + H). This triggers a Python script, which then injects text into the site at a defined position — specifically where the textbox is.

    fetch("http://localhost:5000/type", {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({
    message: response, // IA response from Gemini API. But I get the text first: window.getSelection().toString()
    cursor: cursor
    })
    })
    .then(res => res.json())
    .then(() => {
    throwConsole(`Injected!`, 'ok');
    })
    .catch((e) => {
    throwConsole(`Error: ${e}. Check the server from Python.`, 'error');
    })



    The injection works, but the site still detects the typing as artificial in some cases. I’m using pyautogui to simulate the typing, with a delay between characters, but it seems the detection is based on typing speed or event trust level.

    I want to make the typing simulation faster but still human-like enough (randomized delays, pauses between words, maybe simulated typos) so that it’s less likely to be detected.

    In python, I run a server to catch the information from JS.

    import random
    from flask import Flask, request, jsonify
    from flask_cors import CORS
    import pyautogui
    import keyboard
    import time

    pyautogui.FAILSAFE = False

    app = Flask(__name__)
    CORS(app, supports_credentials=True)

    screen_width, screen_height = pyautogui.size()

    custom_x = int(screen_width / 2 + 100)
    custom_y = int(screen_height / 2)

    def simulate_typing(text):
    for char in text:

    # pyautogui.write(char, interval=0.6)
    pyautogui.typewrite(char)
    time.sleep(random.uniform(0.11, 0.12))



    @app.route("/type", methods=["POST"])
    def type_message():
    if request.method == "OPTIONS":
    response = app.make_response("")
    response.headers["Access-Control-Allow-Origin"] = "*"
    response.headers["Access-Control-Allow-Methods"] = "POST, OPTIONS"
    response.headers["Access-Control-Allow-Headers"] = "Content-Type"
    return response, 200

    try:
    data = request.get_json(force=True)
    message = data.get("message", "")
    cursor = data.get("cursor", {})

    x = cursor.get("x", 0)
    y = cursor.get("y", 0)

    # Set the cursor in the textbox on Seia
    x = custom_x if x == 0 else x
    y = custom_y if y == 0 else y

    pyautogui.click(x=x, y=y)
    simulate_typing(message)


    return jsonify({"status": "ok", "typed": message})
    except Exception as e:
    return jsonify({"status": "error", "message": str(e)}), 500


    if __name__ == "__main__":
    print("============================")
    print(" AntiSeia is running! ")
    print("============================")
    app.run(host="0.0.0.0", port=5000)
    time.sleep(3)



    How can I adjust the Python code to improve the speed while keeping the typing natural and avoiding detection?

    Here is the site of my professor: https://seia-eta.vercel.app/student

    Code: QDS0E65I

    Thanks in advance.

    Continue reading...

Compartilhe esta Página