mouse-keepalive 1.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.md +153 -0
- package/bin/mouse-keepalive.js +80 -0
- package/package.json +51 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 motoish
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
# Mouse Keepalive
|
|
2
|
+
|
|
3
|
+
**中文** | [English](README_EN.md)
|
|
4
|
+
|
|
5
|
+
跨平台 CLI 工具:按固定间隔轻微移动鼠标并立即回位,避免系统因长时间无操作而休眠或锁屏。
|
|
6
|
+
支持 **macOS / Windows / Linux**。
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## ✨ 功能亮点
|
|
11
|
+
|
|
12
|
+
- 跨平台(Python + [pyautogui](https://pypi.org/project/PyAutoGUI/))
|
|
13
|
+
- 可配置移动间隔与总运行时长
|
|
14
|
+
- 瞬时微移(约 1–2 像素),日常使用几乎无感
|
|
15
|
+
- **PyPI** 与 **npm** 均可安装;命令行别名 `mka`
|
|
16
|
+
- 默认输出每次移动日志;`-q` 可完全静默
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## 📋 环境要求
|
|
21
|
+
|
|
22
|
+
| 方式 | 要求 |
|
|
23
|
+
|------|------|
|
|
24
|
+
| **PyPI / pipx**(推荐) | Python **3.11+** |
|
|
25
|
+
| **npm** | Node.js **14+**,且本机已安装 **Python 3.11+**(npm 包为启动器,实际逻辑在 Python 中) |
|
|
26
|
+
| **从源码运行** | Python 3.11+;见下方「本地开发」 |
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## 📦 安装
|
|
31
|
+
|
|
32
|
+
### PyPI(推荐)
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
pip install mouse-keepalive
|
|
36
|
+
# 或(隔离环境,推荐桌面使用)
|
|
37
|
+
pipx install mouse-keepalive
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### npm
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
npm install -g mouse-keepalive
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
首次运行前请确保已安装 Python 3.11+;若缺少 `pyautogui`,npm 入口会尝试自动 `pip install pyautogui`。
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
## 🚀 快速开始
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
# 默认:每 60 秒移动一次,Ctrl+C 停止
|
|
54
|
+
mka
|
|
55
|
+
|
|
56
|
+
# 每 30 秒移动一次
|
|
57
|
+
mka -i 30
|
|
58
|
+
|
|
59
|
+
# 每 2 分钟移动一次,共运行 1 小时
|
|
60
|
+
mka -i 120 -d 3600
|
|
61
|
+
|
|
62
|
+
# 静默模式(无日志)
|
|
63
|
+
mka -q
|
|
64
|
+
|
|
65
|
+
# 帮助
|
|
66
|
+
mka --help
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
等效命令:
|
|
70
|
+
|
|
71
|
+
```text
|
|
72
|
+
mouse-keepalive
|
|
73
|
+
python -m mouse_keepalive
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
## ⚙️ 命令行参数
|
|
79
|
+
|
|
80
|
+
| 参数 | 说明 | 默认 |
|
|
81
|
+
|------|------|------|
|
|
82
|
+
| `-i, --interval` | 移动间隔(秒) | `60` |
|
|
83
|
+
| `-d, --duration` | 运行总时长(秒);省略则一直运行 | 无限 |
|
|
84
|
+
| `-q, --quiet` | 静默模式,不输出日志 | 关闭 |
|
|
85
|
+
| `-h, --help` | 显示帮助 | — |
|
|
86
|
+
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
## 🧠 工作原理
|
|
90
|
+
|
|
91
|
+
程序按间隔获取当前光标位置,偏移 1–2 像素后**立即移回**,使系统仍检测到鼠标活动,同时尽量不打扰正常使用。
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
## 🛠 本地开发
|
|
96
|
+
|
|
97
|
+
仓库采用 **src 布局**,包路径为 `src/mouse_keepalive/`(对外导入名仍为 `mouse_keepalive`)。
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
git clone https://github.com/motoish/mouse-keepalive.git
|
|
101
|
+
cd mouse-keepalive
|
|
102
|
+
|
|
103
|
+
# 可编辑安装 + 开发依赖
|
|
104
|
+
pip install -e ".[dev]"
|
|
105
|
+
|
|
106
|
+
# 方式一:仓库根目录脚本(改代码后无需重装)
|
|
107
|
+
./move_mouse.sh
|
|
108
|
+
./move_mouse.sh -i 30 -q
|
|
109
|
+
|
|
110
|
+
# 方式二:Makefile
|
|
111
|
+
make run ARGS="-i 30"
|
|
112
|
+
|
|
113
|
+
# 方式三:安装后的 CLI
|
|
114
|
+
mka -i 30
|
|
115
|
+
|
|
116
|
+
# 测试与检查
|
|
117
|
+
make test
|
|
118
|
+
make lint
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
`move_mouse.sh` 会优先使用 `.venv/bin/python`,并通过 `PYTHONPATH=src` 加载源码;**不会**随 PyPI/npm 包发布。
|
|
122
|
+
|
|
123
|
+
### 目录结构(简要)
|
|
124
|
+
|
|
125
|
+
```text
|
|
126
|
+
mouse-keepalive/
|
|
127
|
+
├── src/mouse_keepalive/ # Python 包
|
|
128
|
+
├── bin/ # npm CLI(转发到 python -m mouse_keepalive)
|
|
129
|
+
├── tests/
|
|
130
|
+
├── move_mouse.sh # 仅本地开发
|
|
131
|
+
└── pyproject.toml
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
---
|
|
135
|
+
|
|
136
|
+
## ⚠️ 注意事项
|
|
137
|
+
|
|
138
|
+
- 使用 **Ctrl + C** 可随时退出
|
|
139
|
+
- **macOS** 需在「系统设置 → 隐私与安全性 → 辅助功能」中允许终端或 Python
|
|
140
|
+
- 企业安全策略可能拦截模拟鼠标;若无效请联系管理员或加入白名单
|
|
141
|
+
|
|
142
|
+
---
|
|
143
|
+
|
|
144
|
+
## 📦 发布与版本
|
|
145
|
+
|
|
146
|
+
用户安装版本以 [PyPI](https://pypi.org/project/mouse-keepalive/) / [npm](https://www.npmjs.com/package/mouse-keepalive) 为准。
|
|
147
|
+
变更记录见 [CHANGELOG.md](CHANGELOG.md)。仓库使用 [release-please](https://github.com/googleapis/release-please) 管理版本;合并 Release PR 后会发布 `v*` 标签并自动发布到 npm / PyPI。
|
|
148
|
+
|
|
149
|
+
---
|
|
150
|
+
|
|
151
|
+
## 📄 许可证
|
|
152
|
+
|
|
153
|
+
[MIT](LICENSE)
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* npm CLI: delegates to Python module mouse_keepalive.
|
|
4
|
+
* npm CLI:委托给 Python 模块 mouse_keepalive。
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const { spawn } = require('child_process');
|
|
8
|
+
|
|
9
|
+
function tryPython(cmd) {
|
|
10
|
+
return new Promise((resolve) => {
|
|
11
|
+
const proc = spawn(cmd, ['--version'], { stdio: 'pipe' });
|
|
12
|
+
proc.on('close', (code) => resolve(code === 0 ? cmd : null));
|
|
13
|
+
proc.on('error', () => resolve(null));
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async function findPython() {
|
|
18
|
+
for (const cmd of ['python3', 'python']) {
|
|
19
|
+
const found = await tryPython(cmd);
|
|
20
|
+
if (found) return found;
|
|
21
|
+
}
|
|
22
|
+
throw new Error('Python not found. Please install Python 3.11 or higher.');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function checkPyAutogui(pythonCmd) {
|
|
26
|
+
return new Promise((resolve) => {
|
|
27
|
+
const proc = spawn(pythonCmd, ['-c', 'import pyautogui'], { stdio: 'pipe' });
|
|
28
|
+
proc.on('close', (code) => resolve(code === 0));
|
|
29
|
+
proc.on('error', () => resolve(false));
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function installPyAutogui(pythonCmd) {
|
|
34
|
+
return new Promise((resolve, reject) => {
|
|
35
|
+
console.log('警告: pyautogui 未安装,正在尝试安装...');
|
|
36
|
+
console.log('Warning: pyautogui not installed, attempting install...');
|
|
37
|
+
|
|
38
|
+
const pip = spawn(pythonCmd, ['-m', 'pip', 'install', 'pyautogui'], {
|
|
39
|
+
stdio: 'inherit',
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
pip.on('close', (code) => {
|
|
43
|
+
if (code === 0) resolve();
|
|
44
|
+
else reject(new Error('Failed to install pyautogui. Please run: pip install pyautogui'));
|
|
45
|
+
});
|
|
46
|
+
pip.on('error', reject);
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function runPythonModule(pythonCmd, args) {
|
|
51
|
+
const child = spawn(pythonCmd, ['-m', 'mouse_keepalive', ...args], {
|
|
52
|
+
stdio: 'inherit',
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
child.on('close', (code) => process.exit(code || 0));
|
|
56
|
+
child.on('error', (err) => {
|
|
57
|
+
console.error('错误: 无法启动 Python 模块 / Error: Failed to start Python module');
|
|
58
|
+
console.error(err.message);
|
|
59
|
+
process.exit(1);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
process.on('SIGINT', () => child.kill('SIGINT'));
|
|
63
|
+
process.on('SIGTERM', () => child.kill('SIGTERM'));
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async function main() {
|
|
67
|
+
try {
|
|
68
|
+
const pythonCmd = await findPython();
|
|
69
|
+
const hasPyAutogui = await checkPyAutogui(pythonCmd);
|
|
70
|
+
if (!hasPyAutogui) {
|
|
71
|
+
await installPyAutogui(pythonCmd);
|
|
72
|
+
}
|
|
73
|
+
runPythonModule(pythonCmd, process.argv.slice(2));
|
|
74
|
+
} catch (err) {
|
|
75
|
+
console.error(err.message);
|
|
76
|
+
process.exit(1);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
main();
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "mouse-keepalive",
|
|
3
|
+
"version": "1.5.2",
|
|
4
|
+
"description": "A cross-platform tool to automatically move the mouse at specified intervals to prevent system sleep or lock",
|
|
5
|
+
"bin": {
|
|
6
|
+
"mouse-keepalive": "./bin/mouse-keepalive.js",
|
|
7
|
+
"mka": "./bin/mouse-keepalive.js"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"lint": "eslint bin/*.js",
|
|
11
|
+
"format": "prettier --write \"bin/*.js\" \"package.json\""
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"mouse",
|
|
15
|
+
"automation",
|
|
16
|
+
"prevent-sleep",
|
|
17
|
+
"idle",
|
|
18
|
+
"keep-alive",
|
|
19
|
+
"cross-platform",
|
|
20
|
+
"cli",
|
|
21
|
+
"tool",
|
|
22
|
+
"macos",
|
|
23
|
+
"windows",
|
|
24
|
+
"linux"
|
|
25
|
+
],
|
|
26
|
+
"author": "motoish",
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "git+https://github.com/motoish/mouse-keepalive.git"
|
|
31
|
+
},
|
|
32
|
+
"bugs": {
|
|
33
|
+
"url": "https://github.com/motoish/mouse-keepalive/issues"
|
|
34
|
+
},
|
|
35
|
+
"homepage": "https://github.com/motoish/mouse-keepalive#readme",
|
|
36
|
+
"engines": {
|
|
37
|
+
"node": ">=14.0.0"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"eslint": "^8.57.0",
|
|
41
|
+
"prettier": "^3.2.5"
|
|
42
|
+
},
|
|
43
|
+
"files": [
|
|
44
|
+
"bin/",
|
|
45
|
+
"README.md",
|
|
46
|
+
"LICENSE"
|
|
47
|
+
],
|
|
48
|
+
"publishConfig": {
|
|
49
|
+
"access": "public"
|
|
50
|
+
}
|
|
51
|
+
}
|