python test 1

import pyautogui
import time
import random

pyautogui.FAILSAFE = True

def human_horizontal_slide(start_x, start_y, end_x):
    """
    Simulates a human dragging a horizontal slider.
    The Y coordinate remains perfectly constant.
    """
    
    # 1. Warm-up: Move the mouse to the slider's starting handle
    # (Easing out simulates the hand slowing down as it reaches the target)
    move_duration = random.uniform(0.4, 0.7)
    pyautogui.moveTo(start_x, start_y, duration=move_duration, tween=pyautogui.easeOutQuad)
    
    # Human reaction time before clicking
    time.sleep(random.uniform(0.1, 0.25))
    
    # 2. Grab the slider
    pyautogui.mouseDown()
    time.sleep(random.uniform(0.1, 0.3)) # Pause before starting the pull
    
    # 3. The Slide (with variable speed and potential overshoot)
    # Decide if we are going to accidentally overshoot the target (like real humans do)
    will_overshoot = random.random() > 0.5 # 50% chance to overshoot
    
    if will_overshoot:
        # Calculate an overshoot target (e.g., 5 to 15 pixels past the real target)
        direction = 1 if end_x > start_x else -1
        overshoot_x = end_x + (random.randint(5, 15) * direction)
        
        # Fast, confident slide past the target
        slide_duration = random.uniform(0.5, 0.9)
        pyautogui.moveTo(overshoot_x, start_y, duration=slide_duration, tween=pyautogui.easeInOutSine)
        
        # Oops went too far! Tiny pause to realize the mistake
        time.sleep(random.uniform(0.2, 0.4))
        
        # Pull back slowly to the exact correct spot
        correction_duration = random.uniform(0.3, 0.6)
        pyautogui.moveTo(end_x, start_y, duration=correction_duration, tween=pyautogui.easeOutCubic)
        
    else:
        # Normal, careful slide directly to the target
        slide_duration = random.uniform(0.7, 1.2)
        pyautogui.moveTo(end_x, start_y, duration=slide_duration, tween=pyautogui.easeInOutSine)

    # 4. Final pause before releasing the mouse button
    time.sleep(random.uniform(0.1, 0.3))
    pyautogui.mouseUp()

# --- Example Usage ---
# Slider handle is at X: 400, Y: 500. We want to move it to X: 750.
# human_horizontal_slide(400, 500, 750)

 

import time
import random
import pyautogui

def human_slider_drag(start_x, start_y, end_x):
    pyautogui.moveTo(start_x, start_y, duration=random.uniform(0.2, 0.4))
    time.sleep(random.uniform(0.05, 0.15))
    pyautogui.mouseDown()

    x = start_x
    steps = random.randint(8, 15)

    for i in range(steps):
        remaining = end_x - x
        if i == steps - 1:
            next_x = end_x
        else:
            next_x = x + remaining * random.uniform(0.12, 0.22)

        next_y = start_y + random.randint(-2, 2)

        pyautogui.moveTo(
            next_x,
            next_y,
            duration=random.uniform(0.05, 0.18),
            tween=pyautogui.easeInOutQuad
        )

        x = next_x
        time.sleep(random.uniform(0.01, 0.05))

    pyautogui.mouseUp()

human_slider_drag(500, 400, 800)

 https://files.cnblogs.com/files/yyjj/popk.7z?t=1775206585&download=true

 

import ctypes
from ctypes import wintypes

user32 = ctypes.windll.user32
gdi32 = ctypes.windll.gdi32

# ------------------------------------------------------------
# Window Helpers
# ------------------------------------------------------------

def find_window(title: str):
    """Find window by exact title."""
    return user32.FindWindowW(None, title)

def find_window_partial(partial: str):
    """Find window by partial title."""
    hwnd_list = []

    def enum_proc(hwnd, lParam):
        text = ctypes.create_unicode_buffer(512)
        user32.GetWindowTextW(hwnd, text, 512)
        if partial.lower() in text.value.lower():
            hwnd_list.append(hwnd)
        return True

    EnumWindowsProc = ctypes.WINFUNCTYPE(ctypes.c_bool, wintypes.HWND, wintypes.LPARAM)
    user32.EnumWindows(EnumWindowsProc(enum_proc), 0)

    return hwnd_list[0] if hwnd_list else None

def get_window_rect(hwnd):
    """Return (left, top, right, bottom)."""
    rect = wintypes.RECT()
    user32.GetWindowRect(hwnd, ctypes.byref(rect))
    return rect.left, rect.top, rect.right, rect.bottom

def focus_window(hwnd):
    """Bring window to foreground."""
    user32.SetForegroundWindow(hwnd)

def find_sub_window(hwnd, subclass):
    return user32.FindWindowExW(hwnd, None, subclass, None)


# ------------------------------------------------------------
# Mouse Helpers
# ------------------------------------------------------------

class POINT(ctypes.Structure):
    _fields_ = [("x", wintypes.LONG),
                ("y", wintypes.LONG)]

def get_mouse_pos():
    pt = POINT()
    user32.GetCursorPos(ctypes.byref(pt))
    return pt.x, pt.y

# ------------------------------------------------------------
# Pixel Reader
# ------------------------------------------------------------

def get_pixel(x, y):
    """Fast pixel read using WinAPI GetPixel."""
    hdc = user32.GetDC(None)
    color = gdi32.GetPixel(hdc, x, y)
    user32.ReleaseDC(None, hdc)

    r = color & 0xFF
    g = (color >> 8) & 0xFF
    b = (color >> 16) & 0xFF
    return (r, g, b)

# ------------------------------------------------------------
# Send Keys (PostMessage to specific window)
# ------------------------------------------------------------

WM_KEYDOWN = 0x0100
WM_KEYUP   = 0x0101
WM_CHAR    = 0x0102

def send_key_to_window(hwnd, vk_code):
    """Send key directly to window message queue."""
    user32.PostMessageW(hwnd, WM_KEYDOWN, vk_code, 0)
    user32.PostMessageW(hwnd, WM_KEYUP, vk_code, 0)

def send_char_to_window(hwnd, ch):
    vk = ord(ch.upper())  # virtual key
    user32.PostMessageW(hwnd, WM_KEYDOWN, vk, 0)
    user32.PostMessageW(hwnd, WM_CHAR, ord(ch), 0)
    user32.PostMessageW(hwnd, WM_KEYUP, vk, 0)

def send_text_to_window(hwnd, text):
    for ch in text:
        send_char_to_window(hwnd, ch)


# ------------------------------------------------------------
# SendInput (global, fastest real keyboard simulation)
# ------------------------------------------------------------

INPUT_KEYBOARD = 1
KEYEVENTF_KEYUP = 0x0002

class KEYBDINPUT(ctypes.Structure):
    _fields_ = [
        ("wVk", wintypes.WORD),
        ("wScan", wintypes.WORD),
        ("dwFlags", wintypes.DWORD),
        ("time", wintypes.DWORD),
        ("dwExtraInfo", ctypes.c_ulong),
    ]

class INPUT(ctypes.Structure):
    _fields_ = [
        ("type", wintypes.DWORD),
        ("ki", KEYBDINPUT),
    ]

SendInput = user32.SendInput

def tap_key(vk_code):
    """Global key press using SendInput."""
    press = INPUT(type=INPUT_KEYBOARD, ki=KEYBDINPUT(wVk=vk_code))
    release = INPUT(type=INPUT_KEYBOARD, ki=KEYBDINPUT(wVk=vk_code, dwFlags=KEYEVENTF_KEYUP))

    SendInput(1, ctypes.byref(press), ctypes.sizeof(press))
    SendInput(1, ctypes.byref(release), ctypes.sizeof(release))

 

posted on 2026-03-30 10:43  人在做,人在看  阅读(6)  评论(0)    收藏  举报