Skip to content

Arthur-Miyano/code

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 

Repository files navigation

import time import ctypes from ctypes import wintypes import random

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

user32 = ctypes.windll.user32 SCREEN_WIDTH = user32.GetSystemMetrics(0) SCREEN_HEIGHT = user32.GetSystemMetrics(1)

鼠标微动范围

MIN_STEP = 8 MAX_STEP = 45

主循环间隔(随机)

MIN_INTERVAL = 3 MAX_INTERVAL = 9

按键触发概率(百分比)

KEY_TRIGGER_RATE = 32

鼠标点击触发概率

CLICK_TRIGGER_RATE = 18

def get_mouse_position(): point = POINT() user32.GetCursorPos(ctypes.byref(point)) return point.x, point.y

def set_mouse_position(x, y): user32.SetCursorPos(int(x), int(y))

def simulate_key_press(): """随机模拟Shift轻按,模拟无意识按键""" VK_SHIFT = 0x10 user32.keybd_event(VK_SHIFT, 0, 0, 0) time.sleep(random.uniform(0.04, 0.18)) user32.keybd_event(VK_SHIFT, 0, 0x0002, 0)

def simulate_mouse_click(): """模拟左键单击,模拟真人点击空白处""" # 左键按下 user32.mouse_event(2, 0, 0, 0, 0) time.sleep(random.uniform(0.06, 0.2)) # 左键松开 user32.mouse_event(4, 0, 0, 0, 0)

def curve_move_to(start_x, start_y, target_x, target_y, steps=12): """ 曲线平滑移动:模拟人手缓慢移动,而不是瞬间瞬移 """ for i in range(1, steps + 1): ratio = i / steps # 加入正弦曲线扰动,模拟手腕自然抖动 curve_offset = random.uniform(-2.2, 2.2) * (1 - ratio) cur_x = start_x + (target_x - start_x) * ratio + curve_offset cur_y = start_y + (target_y - start_y) * ratio + curve_offset set_mouse_position(cur_x, cur_y) time.sleep(random.uniform(0.015, 0.035))

def calculate_safe_position(x, y): step = random.randint(MIN_STEP, MAX_STEP) direction = random.choice(["right", "left", "up", "down"])

if direction == "right" and x + step < SCREEN_WIDTH:
    return x + step, y
elif direction == "left" and x - step >= 0:
    return x - step, y
elif direction == "up" and y - step >= 0:
    return x, y - step
elif direction == "down" and y + step < SCREEN_HEIGHT:
    return x, y + step
else:
    return calculate_safe_position(x, y)

def main(): print("Human-like mouse mover started. Ctrl+C to stop.") try: while True: orig_x, orig_y = get_mouse_position() dest_x, dest_y = calculate_safe_position(orig_x, orig_y)

        # 平滑曲线移动过去
        curve_move_to(orig_x, orig_y, dest_x, dest_y)
        time.sleep(random.uniform(0.08, 0.22))

        # 随机触发单击动作(18%概率)
        if random.randint(1, 100) <= CLICK_TRIGGER_RATE:
            time.sleep(random.uniform(0.2, 0.8))
            simulate_mouse_click()

        # 平滑移回原位
        curve_move_to(dest_x, dest_y, orig_x, orig_y)

        # 随机概率触发按键,非固定出现
        if random.randint(1, 100) <= KEY_TRIGGER_RATE:
            time.sleep(random.uniform(0.4, 1.4))
            simulate_key_press()

        # 下一轮等待随机时长
        wait = random.randint(MIN_INTERVAL, MAX_INTERVAL)
        time.sleep(wait)
except KeyboardInterrupt:
    print("\nStopped.")

if name == "main": main()

当前使用Streamlit开发界面,现有问题:点击Run estimation按钮之后渲染出的Run‑status运行状态栏,只要用户点击空白区域、页面触发重新运行,状态栏几秒后就直接消失。

按照以下规则重构代码,原有变量、状态文本、获取latest_job的逻辑全部保留,只修改代码运行层级:

  1. 在会话状态 st.session_state 里初始化一个 st.empty() 固定容器,用来承载Run status板块,页面每次自动刷新时容器不会被销毁。
  2. 将全部Run‑status渲染代码移出按钮点击的if分支,不再只在点击按钮时执行。页面每一次重执行,都会主动读取最新任务状态并渲染状态栏。
  3. Run estimation按钮内部只保留提交任务的业务逻辑,执行完成后调用 st.rerun,按钮区块不再编写UI展示代码。
  4. 使用 @st.fragment 装饰器,当任务状态为running或者queued时,每2秒自动刷新一次页面,实时更新运行进度,不需要用户手动点击。
  5. 最终效果:无论点击空白、切换输入项,Run‑status面板一直持续显示,直到任务执行完毕才稳定展示最终结果,不会无故消失。 输出修改完毕的对应代码块。

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors