手机浏览器访问 https://your-domain.example.com,登录后通过 WebSocket 把键盘、文本、剪贴板、鼠标事件实时发送到 Windows 主机,由 Python 服务注入为真实输入事件。
iOS 客户端:本项目提供原生 iOS 客户端,但 iOS 端不开源。如需购买授权、安装包或定制支持,请单独联系作者付费购买。
web-inputer/
app/
__init__.py
auth.py # 登录、JWT session、限流、来源校验
config.py # 环境变量配置
input_controller.py # pywin32/pynput 键盘鼠标剪贴板注入
main.py # FastAPI + WebSocket + 静态前端
static/
index.html
styles.css
app.js
manifest.webmanifest
sw.js
deploy/
cloudflared-aiapi.yml
remote-input.service
cloudflared-aiapi.service
scripts/
start-dev.ps1
install-nssm-service.ps1
uninstall-nssm-service.ps1
install-cloudflared-windows.ps1
requirements.txt
.env.example
Dockerfile
docker-compose.yml
run.py
- FastAPI + WebSocket 实时通信
- 手机端深色移动 UI,支持 iPhone Safari
- 字母、数字、Enter、Ctrl、Alt、Shift、Win、Backspace、方向键
- 组合键:先点 Ctrl/Alt/Shift/Win 锁定,再点其他键,再点一次释放
- 长按:按住字母/数字按钮会发送 key down/up
- 文本输入:通过剪贴板粘贴,适合中文和长文本
- 心跳检测和延迟显示
- 自动断线重连
- 多客户端控制锁
- 登录密码 + JWT session cookie
- WebSocket 鉴权和 Origin 校验
- 登录限流、输入事件限流、日志记录 IP
- 可用 NSSM 注册 Windows Service,开机自启、后台运行、崩溃恢复
- Cloudflare Tunnel 反向代理到本地服务,支持 HTTPS/WSS
本项目的页面源码在 frontend/,使用 Vue 3 + Vite + pnpm + Naive UI。生产仍由 FastAPI 服务 app/static/dist 的构建产物。
pnpm --dir frontend install
pnpm --dir frontend build生产构建产物会输出到 app/static/dist/,并由 FastAPI 直接托管。app/static/dist/assets/*.js 和 *.css 在 Git 中固定为 LF 换行,避免 Windows 重复构建后出现仅换行导致的脏状态。
开发时先启动后端,再启动 Vite:
.\.venv\Scripts\python.exe -X utf8 -m uvicorn app.main:app --host 127.0.0.1 --port 8790 --reload --proxy-headers --forwarded-allow-ips='*'
pnpm --dir frontend dev推送到 main 会触发 .github/workflows/build.yml 构建 Windows EXE artifact。创建并推送 v* 标签会额外创建 GitHub Release,并上传 remote-input.exe。
git push origin main
git tag vX.Y.Z
git push origin vX.Y.Z每个 PR 和 main 推送还会运行 .github/workflows/ci.yml,使用锁定的 pnpm lockfile 构建 frontend/。当前前端没有单独的 lint 或 typecheck 脚本,因此 CI 不会伪造这类检查。
- 安装 Python 3.11+。
- 复制环境变量:
Copy-Item .env.example .env- 修改
.env:
SECRET_KEY=至少32位随机字符串,建议64位
ADMIN_PASSWORD=你的强密码
PUBLIC_ORIGIN=https://your-domain.example.com
ALLOWED_ORIGINS=https://your-domain.example.com
DIRECT_PROBE_PORT=8790
SESSION_TTL_SECONDS=28800
TRUSTED_DEVICE_SESSION_TTL_SECONDS=2592000- 启动:
.\scripts\start-dev.ps1- 本机测试:
Invoke-WebRequest http://127.0.0.1:8790/health注意:生产通过 Cloudflare 访问时 cookie 使用
Secure,必须走 HTTPS。直接用http://127.0.0.1:8790登录时浏览器可能不会保存 Secure Cookie。
下面示例中的 your-domain.example.com 是同一个占位域名;实际部署时请将它统一替换为自己的域名,并保持 PUBLIC_ORIGIN、ALLOWED_ORIGINS 和 Tunnel 的 hostname 完全一致。
隧道名:aiapi
域名:your-domain.example.com
配置文件:deploy/cloudflared-aiapi.yml
tunnel: aiapi
credentials-file: C:\\Users\\<YOU>\\.cloudflared\\aiapi.json
originRequest:
connectTimeout: 10s
keepAliveConnections: 100
keepAliveTimeout: 90s
noTLSVerify: false
ingress:
- hostname: your-domain.example.com
service: http://127.0.0.1:8790
- service: http_status:404首次创建隧道和 DNS:
cloudflared tunnel login
cloudflared tunnel create aiapi
cloudflared tunnel route dns aiapi your-domain.example.com前台测试:
cloudflared tunnel --config .\deploy\cloudflared-aiapi.yml run aiapiWindows service 安装:
.\scripts\install-cloudflared-windows.ps1Cloudflare Tunnel 会自动重连,WebSocket 会通过 wss://your-domain.example.com/ws 工作。
下载 NSSM 后确保 nssm.exe 在 PATH,或传入完整路径。
安装并启动:
.\scripts\install-nssm-service.ps1 -ServiceName RemoteInput -NssmPath C:\tools\nssm\win64\nssm.exe停止:
nssm stop RemoteInput启动:
nssm start RemoteInput卸载:
.\scripts\uninstall-nssm-service.ps1 -ServiceName RemoteInput -NssmPath C:\tools\nssm\win64\nssm.exe查看日志:
Get-Content .\logs\remote-input.log -Tail 100
Get-Content .\logs\service-err.log -Tail 100如果后端部署在 Linux,可参考:
deploy/remote-input.servicedeploy/cloudflared-aiapi.service
但键盘注入目标是 Windows 主机,因此实际控制 Windows 键盘时应在 Windows 上运行 Python 服务。
POST /api/login:提交{ "password": "...", "keepSignedIn": false },成功后写入remote_input_sessionHttpOnly cookie;勾选记住登录状态时使用长期可信设备 session。POST /api/logout:清除 session。GET /api/session:检查登录状态。GET /health:健康检查。GET /api/direct-probe?host=...&port=...:未登录时用于直连自动切换的受限探测;仅接受字面量 Tailscale IPv4 和DIRECT_PROBE_PORT,并按来源 IP 限速。WS /ws:实时输入通道,必须携带 session cookie,且 Origin 必须匹配.env的PUBLIC_ORIGIN或ALLOWED_ORIGINS。
WebSocket 输入消息示例:
{ "type": "input", "action": "tap", "key": "enter" }
{ "type": "input", "action": "down", "key": "ctrl" }
{ "type": "input", "action": "tap", "key": "c" }
{ "type": "input", "action": "up", "key": "ctrl" }
{ "type": "input", "action": "text", "text": "hello" }
{ "type": "input", "action": "mouse_move", "x": 12, "y": -4 }ADMIN_PASSWORD使用强密码,不要提交.env。SECRET_KEY使用随机 64 位以上字符串。- Cloudflare Access 可额外套一层邮箱/OTP 鉴权。
- Cloudflare WAF 可给
/api/login添加速率规则。 - 只监听
127.0.0.1:8790,不要直接暴露本机端口。 - 保持
PUBLIC_ORIGIN=https://your-domain.example.com,避免其他 Origin 建立 WebSocket。 - “记住登录状态”不会在前端保存明文密码,只会签发更长有效期的 HttpOnly session cookie;未勾选使用
SESSION_TTL_SECONDS,勾选使用TRUSTED_DEVICE_SESSION_TTL_SECONDS。 - 日志文件默认在
logs/remote-input.log,包含登录失败、限流和 WebSocket 连接 IP。 - 直连自动探测在登录前仍可用,但
/api/direct-probe只允许字面量 Tailscale IPv4(100.64.0.0/10)和配置的DIRECT_PROBE_PORT,拒绝 DNS、环回、局域网、链路本地、云元数据和任意端口目标。
后端语法检查:
.\.venv\Scripts\python.exe -X utf8 -m compileall app启动调试:
.\.venv\Scripts\python.exe -X utf8 -m uvicorn app.main:app --host 127.0.0.1 --port 8790 --reload --proxy-headers --forwarded-allow-ips='*'Cloudflare 调试:
cloudflared tunnel --loglevel debug --config .\deploy\cloudflared-aiapi.yml run aiapi浏览器调试:
- 打开 Safari/Chrome 开发者工具,查看 WebSocket
/ws是否 101 Switching Protocols。 - 登录成功但 WebSocket 断开时,检查
.env的PUBLIC_ORIGIN是否精确等于https://your-domain.example.com。
原因通常是直接用 HTTP 访问,本项目 cookie 开启 Secure。生产请使用 https://your-domain.example.com。
通常是 Origin 不匹配或 session cookie 缺失。检查:
PUBLIC_ORIGIN=https://your-domain.example.com
ALLOWED_ORIGINS=https://your-domain.example.com- 确认服务运行在当前桌面用户会话中。Windows Service 在 Session 0 中可能无法控制当前交互桌面。
- 如果 NSSM 服务无法注入当前桌面,改用“任务计划程序:用户登录时运行”启动
python run.py。 - 以管理员启动服务通常无法控制非管理员窗口,目标程序权限需要一致。
文本输入使用剪贴板 + Ctrl+V,这是 Windows 上最稳定的跨语言输入方式。单个按键事件主要适合英文、数字和控制键。
- 确认 Python 服务在
127.0.0.1:8790正常。 - 确认
cloudflared-aiapi.yml的 credentials-file 路径正确。 - 前台运行
cloudflared tunnel --loglevel debug ...查看错误。
Docker 可用于开发或非 Windows 环境,但容器内无法直接注入 Windows 桌面键盘事件。
docker compose up --build