nautogui 0.3.1
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 +201 -0
- package/README.md +212 -0
- package/README.zh-CN.md +212 -0
- package/bin/mouseinfo.mjs +8 -0
- package/dist/backend.d.ts +59 -0
- package/dist/backend.d.ts.map +1 -0
- package/dist/backend.js +210 -0
- package/dist/backend.js.map +1 -0
- package/dist/config.d.ts +38 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +60 -0
- package/dist/config.js.map +1 -0
- package/dist/constants.d.ts +16 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +209 -0
- package/dist/constants.js.map +1 -0
- package/dist/coords.d.ts +12 -0
- package/dist/coords.d.ts.map +1 -0
- package/dist/coords.js +46 -0
- package/dist/coords.js.map +1 -0
- package/dist/display-mouse.d.ts +3 -0
- package/dist/display-mouse.d.ts.map +1 -0
- package/dist/display-mouse.js +25 -0
- package/dist/display-mouse.js.map +1 -0
- package/dist/easing-all.d.ts +77 -0
- package/dist/easing-all.d.ts.map +1 -0
- package/dist/easing-all.js +231 -0
- package/dist/easing-all.js.map +1 -0
- package/dist/easing-base.d.ts +8 -0
- package/dist/easing-base.d.ts.map +1 -0
- package/dist/easing-base.js +3 -0
- package/dist/easing-base.js.map +1 -0
- package/dist/easing.d.ts +9 -0
- package/dist/easing.d.ts.map +1 -0
- package/dist/easing.js +15 -0
- package/dist/easing.js.map +1 -0
- package/dist/exceptions.d.ts +18 -0
- package/dist/exceptions.d.ts.map +1 -0
- package/dist/exceptions.js +30 -0
- package/dist/exceptions.js.map +1 -0
- package/dist/hold-context.d.ts +10 -0
- package/dist/hold-context.d.ts.map +1 -0
- package/dist/hold-context.js +31 -0
- package/dist/hold-context.js.map +1 -0
- package/dist/index.d.ts +104 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +362 -0
- package/dist/index.js.map +1 -0
- package/dist/keyboard-utils.d.ts +7 -0
- package/dist/keyboard-utils.d.ts.map +1 -0
- package/dist/keyboard-utils.js +33 -0
- package/dist/keyboard-utils.js.map +1 -0
- package/dist/locate-haystack.d.ts +14 -0
- package/dist/locate-haystack.d.ts.map +1 -0
- package/dist/locate-haystack.js +90 -0
- package/dist/locate-haystack.js.map +1 -0
- package/dist/locate-window.d.ts +12 -0
- package/dist/locate-window.d.ts.map +1 -0
- package/dist/locate-window.js +78 -0
- package/dist/locate-window.js.map +1 -0
- package/dist/log-screenshots.d.ts +3 -0
- package/dist/log-screenshots.d.ts.map +1 -0
- package/dist/log-screenshots.js +32 -0
- package/dist/log-screenshots.js.map +1 -0
- package/dist/mouseinfo.d.ts +8 -0
- package/dist/mouseinfo.d.ts.map +1 -0
- package/dist/mouseinfo.js +83 -0
- package/dist/mouseinfo.js.map +1 -0
- package/dist/msgbox.d.ts +17 -0
- package/dist/msgbox.d.ts.map +1 -0
- package/dist/msgbox.js +77 -0
- package/dist/msgbox.js.map +1 -0
- package/dist/native-msgbox.d.ts +13 -0
- package/dist/native-msgbox.d.ts.map +1 -0
- package/dist/native-msgbox.js +222 -0
- package/dist/native-msgbox.js.map +1 -0
- package/dist/native-utils.d.ts +8 -0
- package/dist/native-utils.d.ts.map +1 -0
- package/dist/native-utils.js +24 -0
- package/dist/native-utils.js.map +1 -0
- package/dist/pixel.d.ts +9 -0
- package/dist/pixel.d.ts.map +1 -0
- package/dist/pixel.js +14 -0
- package/dist/pixel.js.map +1 -0
- package/dist/region.d.ts +14 -0
- package/dist/region.d.ts.map +1 -0
- package/dist/region.js +13 -0
- package/dist/region.js.map +1 -0
- package/dist/run.d.ts +9 -0
- package/dist/run.d.ts.map +1 -0
- package/dist/run.js +189 -0
- package/dist/run.js.map +1 -0
- package/dist/runtime.d.ts +12 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +53 -0
- package/dist/runtime.js.map +1 -0
- package/dist/windows.d.ts +30 -0
- package/dist/windows.d.ts.map +1 -0
- package/dist/windows.js +62 -0
- package/dist/windows.js.map +1 -0
- package/package.json +63 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
# nautogui
|
|
2
|
+
|
|
3
|
+
**English** | [中文](README.zh-CN.md)
|
|
4
|
+
|
|
5
|
+
Cross-platform GUI automation for Node.js: **mouse, keyboard, screenshot, image template locate**. No LLM.
|
|
6
|
+
|
|
7
|
+
| Backend | Purpose |
|
|
8
|
+
|---------|---------|
|
|
9
|
+
| [`@nut-tree/nut-js`](https://nutjs.dev/) | OS mouse / keyboard / screen |
|
|
10
|
+
| `sharp` | `locate()` / `locateAll()` in haystack images |
|
|
11
|
+
|
|
12
|
+
## Install
|
|
13
|
+
|
|
14
|
+
### From npm (after publish)
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install nautogui
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Dependencies `@nut-tree/nut-js` and `sharp` are installed **automatically** with the package.
|
|
21
|
+
|
|
22
|
+
### Local package (development / before publish)
|
|
23
|
+
|
|
24
|
+
Source lives in `nautogui/`. Build first (`tsc` → `dist/`) before use.
|
|
25
|
+
|
|
26
|
+
#### Option A: Monorepo reference (default in this repo)
|
|
27
|
+
|
|
28
|
+
In the root `package.json`:
|
|
29
|
+
|
|
30
|
+
```json
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"nautogui": "file:nautogui"
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
```powershell
|
|
37
|
+
# repo root
|
|
38
|
+
cd nautogui
|
|
39
|
+
npm install
|
|
40
|
+
npm run build
|
|
41
|
+
|
|
42
|
+
cd ..\..
|
|
43
|
+
npm install
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Then any subproject can:
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
import * as nautogui from "nautogui";
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Root `npm run build:tsc` / `npm test` runs `build:nautogui` to compile the local package first.
|
|
53
|
+
|
|
54
|
+
#### Option B: Install from a local path in another project
|
|
55
|
+
|
|
56
|
+
```powershell
|
|
57
|
+
npm install D:\WorkSpace\nautogui
|
|
58
|
+
# or relative path
|
|
59
|
+
npm install ../nautogui
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Your `package.json` will contain something like:
|
|
63
|
+
|
|
64
|
+
```json
|
|
65
|
+
"nautogui": "file:../nautogui"
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
After editing nautogui source, rebuild:
|
|
69
|
+
|
|
70
|
+
```powershell
|
|
71
|
+
cd nautogui
|
|
72
|
+
npm run build
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
#### Option C: Pack as `.tgz` and install
|
|
76
|
+
|
|
77
|
+
```powershell
|
|
78
|
+
cd nautogui
|
|
79
|
+
npm install
|
|
80
|
+
npm run build
|
|
81
|
+
npm pack
|
|
82
|
+
# creates nautogui-0.3.0.tgz
|
|
83
|
+
|
|
84
|
+
cd ..\your-other-project
|
|
85
|
+
npm install D:\WorkSpace\nautogui\nautogui-0.3.0.tgz
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
#### Option D: Global link (local integration testing)
|
|
89
|
+
|
|
90
|
+
```powershell
|
|
91
|
+
cd nautogui
|
|
92
|
+
npm install
|
|
93
|
+
npm run build
|
|
94
|
+
npm link
|
|
95
|
+
|
|
96
|
+
cd ..\your-other-project
|
|
97
|
+
npm link nautogui
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
To unlink: `npm unlink nautogui` (in your project) and `npm unlink -g nautogui` (in the nautogui directory).
|
|
101
|
+
|
|
102
|
+
### CLI (optional)
|
|
103
|
+
|
|
104
|
+
After build and install:
|
|
105
|
+
|
|
106
|
+
```powershell
|
|
107
|
+
npx nautogui-mouseinfo
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Shows live mouse coordinates (floating window on Windows, terminal elsewhere).
|
|
111
|
+
|
|
112
|
+
## Quick start
|
|
113
|
+
|
|
114
|
+
All API calls are **async**.
|
|
115
|
+
|
|
116
|
+
### Keyboard and mouse
|
|
117
|
+
|
|
118
|
+
```typescript
|
|
119
|
+
import * as nautogui from "nautogui";
|
|
120
|
+
|
|
121
|
+
const { width: screenWidth, height: screenHeight } = await nautogui.size();
|
|
122
|
+
const { x: currentMouseX, y: currentMouseY } = await nautogui.position();
|
|
123
|
+
|
|
124
|
+
await nautogui.moveTo(100, 150);
|
|
125
|
+
await nautogui.click();
|
|
126
|
+
await nautogui.click(200, 220);
|
|
127
|
+
await nautogui.move(0, 10); // relative: 10px down
|
|
128
|
+
await nautogui.doubleClick();
|
|
129
|
+
await nautogui.moveTo(500, 500, { duration: 2, tween: nautogui.easeInOutQuad });
|
|
130
|
+
await nautogui.write("Hello world!", { interval: 0.25 });
|
|
131
|
+
await nautogui.press("esc");
|
|
132
|
+
await nautogui.keyDown("shift");
|
|
133
|
+
await nautogui.write(["left", "left", "left", "left", "left", "left"]);
|
|
134
|
+
await nautogui.keyUp("shift");
|
|
135
|
+
await nautogui.hotkey("ctrl", "c");
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### Screenshots
|
|
139
|
+
|
|
140
|
+
```typescript
|
|
141
|
+
import * as nautogui from "nautogui";
|
|
142
|
+
|
|
143
|
+
const path1 = await nautogui.screenshot();
|
|
144
|
+
const path2 = await nautogui.screenshot("my_screenshot2.png");
|
|
145
|
+
await nautogui.screenshot("region.png", { left: 0, top: 0, width: 400, height: 300 });
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### Image template locate
|
|
149
|
+
|
|
150
|
+
```typescript
|
|
151
|
+
import * as nautogui from "nautogui";
|
|
152
|
+
|
|
153
|
+
const button7location = await nautogui.locateOnScreen("button.png");
|
|
154
|
+
// → { left: 1416, top: 562, width: 50, height: 41 }
|
|
155
|
+
|
|
156
|
+
if (button7location) {
|
|
157
|
+
const { x: buttonx, y: buttony } = nautogui.center(button7location);
|
|
158
|
+
await nautogui.click(buttonx, buttony);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const centerPt = await nautogui.locateCenterOnScreen("button.png");
|
|
162
|
+
if (centerPt) {
|
|
163
|
+
await nautogui.click(centerPt.x, centerPt.y);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const box = await nautogui.locate("button.png", "haystack.png");
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### Message boxes
|
|
170
|
+
|
|
171
|
+
```typescript
|
|
172
|
+
await nautogui.alert("This is an alert box.");
|
|
173
|
+
await nautogui.confirm("Shall I proceed?");
|
|
174
|
+
await nautogui.confirm("Enter option.", { buttons: ["A", "B", "C"] });
|
|
175
|
+
await nautogui.prompt("What is your name?");
|
|
176
|
+
await nautogui.password("Enter password (text will be hidden)");
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
### Runnable examples
|
|
180
|
+
|
|
181
|
+
```powershell
|
|
182
|
+
cd nautogui
|
|
183
|
+
npm run build
|
|
184
|
+
npm run fixtures
|
|
185
|
+
node examples/01-keyboard-mouse-control.mjs # dry-run
|
|
186
|
+
node examples/01-keyboard-mouse-control.mjs --live # real mouse/keyboard
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
See [examples/README.md](./examples/README.md) for all example scripts.
|
|
190
|
+
|
|
191
|
+
## Design
|
|
192
|
+
|
|
193
|
+
- Operations use **screen coordinates (x, y)** or **PNG template images**
|
|
194
|
+
- `locateOnScreen('button.png')` uses nut.js template matching
|
|
195
|
+
- **No** LLM / natural-language UI locating
|
|
196
|
+
|
|
197
|
+
For “describe UI → find coordinates”, wire a vision model in your **host app** (e.g. this repo’s browser/desktop vision + Stagehand Agent), then call `nautogui.click(x, y)`.
|
|
198
|
+
|
|
199
|
+
## Build & pack
|
|
200
|
+
|
|
201
|
+
```bash
|
|
202
|
+
cd nautogui
|
|
203
|
+
npm install && npm run build && npm pack && npm test
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
## Notes
|
|
207
|
+
|
|
208
|
+
1. All functions are **async** (`await`).
|
|
209
|
+
2. **msgbox** uses native OS dialogs when available, else readline.
|
|
210
|
+
3. Primary monitor only.
|
|
211
|
+
|
|
212
|
+
Apache-2.0
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
# nautogui
|
|
2
|
+
|
|
3
|
+
[English](README.md) | **中文**
|
|
4
|
+
|
|
5
|
+
Node.js 跨平台 GUI 自动化:**鼠标、键盘、截图、图像模板定位**。不含大模型。
|
|
6
|
+
|
|
7
|
+
| 后端 | 用途 |
|
|
8
|
+
|------|------|
|
|
9
|
+
| [`@nut-tree/nut-js`](https://nutjs.dev/) | 操作系统级鼠标 / 键盘 / 屏幕 |
|
|
10
|
+
| `sharp` | 在 haystack 图像中执行 `locate()` / `locateAll()` |
|
|
11
|
+
|
|
12
|
+
## 安装
|
|
13
|
+
|
|
14
|
+
### 从 npm 安装(发布后)
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install nautogui
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
依赖 `@nut-tree/nut-js`、`sharp` 会随包**自动安装**。
|
|
21
|
+
|
|
22
|
+
### 本地包安装(开发 / 未发布时)
|
|
23
|
+
|
|
24
|
+
源码在 `nautogui/`,使用前需先 **构建**(`tsc` → `dist/`)。
|
|
25
|
+
|
|
26
|
+
#### 方式 A:Monorepo 内引用(本仓库默认)
|
|
27
|
+
|
|
28
|
+
在仓库根目录 `package.json` 中:
|
|
29
|
+
|
|
30
|
+
```json
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"nautogui": "file:nautogui"
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
```powershell
|
|
37
|
+
# 仓库根目录
|
|
38
|
+
cd nautogui
|
|
39
|
+
npm install
|
|
40
|
+
npm run build
|
|
41
|
+
|
|
42
|
+
cd ..\..
|
|
43
|
+
npm install
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
之后任意子项目可:
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
import * as nautogui from "nautogui";
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
根目录 `npm run build:tsc` / `npm test` 会先执行 `build:nautogui` 编译本地包。
|
|
53
|
+
|
|
54
|
+
#### 方式 B:其他项目引用本地路径
|
|
55
|
+
|
|
56
|
+
```powershell
|
|
57
|
+
npm install D:\WorkSpace\nautogui
|
|
58
|
+
# 或相对路径
|
|
59
|
+
npm install ../nautogui
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
`package.json` 会出现类似:
|
|
63
|
+
|
|
64
|
+
```json
|
|
65
|
+
"nautogui": "file:../nautogui"
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
修改 nautogui 源码后需重新构建:
|
|
69
|
+
|
|
70
|
+
```powershell
|
|
71
|
+
cd nautogui
|
|
72
|
+
npm run build
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
#### 方式 C:打包成 `.tgz` 再安装
|
|
76
|
+
|
|
77
|
+
```powershell
|
|
78
|
+
cd nautogui
|
|
79
|
+
npm install
|
|
80
|
+
npm run build
|
|
81
|
+
npm pack
|
|
82
|
+
# 生成 nautogui-0.3.0.tgz
|
|
83
|
+
|
|
84
|
+
cd ..\your-other-project
|
|
85
|
+
npm install D:\WorkSpace\nautogui\nautogui-0.3.0.tgz
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
#### 方式 D:全局链接(本地联调)
|
|
89
|
+
|
|
90
|
+
```powershell
|
|
91
|
+
cd nautogui
|
|
92
|
+
npm install
|
|
93
|
+
npm run build
|
|
94
|
+
npm link
|
|
95
|
+
|
|
96
|
+
cd ..\your-other-project
|
|
97
|
+
npm link nautogui
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
取消链接:`npm unlink nautogui`(在项目目录)+ `npm unlink -g nautogui`(在 nautogui 目录)。
|
|
101
|
+
|
|
102
|
+
### CLI(可选)
|
|
103
|
+
|
|
104
|
+
构建并安装后可用:
|
|
105
|
+
|
|
106
|
+
```powershell
|
|
107
|
+
npx nautogui-mouseinfo
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
显示实时鼠标坐标(Windows 为浮窗,其他平台为终端)。
|
|
111
|
+
|
|
112
|
+
## 快速上手
|
|
113
|
+
|
|
114
|
+
所有 API 均为 **async**。
|
|
115
|
+
|
|
116
|
+
### 键盘与鼠标
|
|
117
|
+
|
|
118
|
+
```typescript
|
|
119
|
+
import * as nautogui from "nautogui";
|
|
120
|
+
|
|
121
|
+
const { width: screenWidth, height: screenHeight } = await nautogui.size();
|
|
122
|
+
const { x: currentMouseX, y: currentMouseY } = await nautogui.position();
|
|
123
|
+
|
|
124
|
+
await nautogui.moveTo(100, 150);
|
|
125
|
+
await nautogui.click();
|
|
126
|
+
await nautogui.click(200, 220);
|
|
127
|
+
await nautogui.move(0, 10); // 相对移动:向下 10px
|
|
128
|
+
await nautogui.doubleClick();
|
|
129
|
+
await nautogui.moveTo(500, 500, { duration: 2, tween: nautogui.easeInOutQuad });
|
|
130
|
+
await nautogui.write("Hello world!", { interval: 0.25 });
|
|
131
|
+
await nautogui.press("esc");
|
|
132
|
+
await nautogui.keyDown("shift");
|
|
133
|
+
await nautogui.write(["left", "left", "left", "left", "left", "left"]);
|
|
134
|
+
await nautogui.keyUp("shift");
|
|
135
|
+
await nautogui.hotkey("ctrl", "c");
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### 截图
|
|
139
|
+
|
|
140
|
+
```typescript
|
|
141
|
+
import * as nautogui from "nautogui";
|
|
142
|
+
|
|
143
|
+
const path1 = await nautogui.screenshot();
|
|
144
|
+
const path2 = await nautogui.screenshot("my_screenshot2.png");
|
|
145
|
+
await nautogui.screenshot("region.png", { left: 0, top: 0, width: 400, height: 300 });
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### 图像模板定位
|
|
149
|
+
|
|
150
|
+
```typescript
|
|
151
|
+
import * as nautogui from "nautogui";
|
|
152
|
+
|
|
153
|
+
const button7location = await nautogui.locateOnScreen("button.png");
|
|
154
|
+
// → { left: 1416, top: 562, width: 50, height: 41 }
|
|
155
|
+
|
|
156
|
+
if (button7location) {
|
|
157
|
+
const { x: buttonx, y: buttony } = nautogui.center(button7location);
|
|
158
|
+
await nautogui.click(buttonx, buttony);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const centerPt = await nautogui.locateCenterOnScreen("button.png");
|
|
162
|
+
if (centerPt) {
|
|
163
|
+
await nautogui.click(centerPt.x, centerPt.y);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const box = await nautogui.locate("button.png", "haystack.png");
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### 消息框
|
|
170
|
+
|
|
171
|
+
```typescript
|
|
172
|
+
await nautogui.alert("This is an alert box.");
|
|
173
|
+
await nautogui.confirm("Shall I proceed?");
|
|
174
|
+
await nautogui.confirm("Enter option.", { buttons: ["A", "B", "C"] });
|
|
175
|
+
await nautogui.prompt("What is your name?");
|
|
176
|
+
await nautogui.password("Enter password (text will be hidden)");
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
### 可运行示例
|
|
180
|
+
|
|
181
|
+
```powershell
|
|
182
|
+
cd nautogui
|
|
183
|
+
npm run build
|
|
184
|
+
npm run fixtures
|
|
185
|
+
node examples/01-keyboard-mouse-control.mjs # dry-run
|
|
186
|
+
node examples/01-keyboard-mouse-control.mjs --live # 真实鼠标/键盘
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
全部示例见 [examples/README.zh-CN.md](./examples/README.zh-CN.md)。
|
|
190
|
+
|
|
191
|
+
## 设计说明
|
|
192
|
+
|
|
193
|
+
- 操作基于 **屏幕坐标 (x, y)** 或 **PNG 模板图**
|
|
194
|
+
- `locateOnScreen('button.png')` 使用 nut.js 模板匹配
|
|
195
|
+
- **不包含**大模型 / 自然语言定位
|
|
196
|
+
|
|
197
|
+
若需要「描述 UI → 找坐标」,请在**上层应用**(如本仓库的浏览器/桌面视觉 + Stagehand Agent)接入视觉模型,再调用 `nautogui.click(x, y)`。
|
|
198
|
+
|
|
199
|
+
## 构建与打包
|
|
200
|
+
|
|
201
|
+
```bash
|
|
202
|
+
cd nautogui
|
|
203
|
+
npm install && npm run build && npm pack && npm test
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
## 说明
|
|
207
|
+
|
|
208
|
+
1. 所有函数均为 **async**(需 `await`)。
|
|
209
|
+
2. **msgbox** 优先使用原生系统对话框,否则回退到 readline。
|
|
210
|
+
3. 仅主显示器。
|
|
211
|
+
|
|
212
|
+
Apache-2.0
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OS input backend via optional @nut-tree/nut-js (Windows / macOS / Linux).
|
|
3
|
+
*/
|
|
4
|
+
import type { Point } from "./easing-base.js";
|
|
5
|
+
import type { Box } from "./region.js";
|
|
6
|
+
export type NutModule = typeof import("@nut-tree/nut-js");
|
|
7
|
+
export type FindImageOptions = {
|
|
8
|
+
confidence?: number;
|
|
9
|
+
region?: Box;
|
|
10
|
+
};
|
|
11
|
+
export declare function loadNutJs(): Promise<NutModule | null>;
|
|
12
|
+
export declare function getNut(): Promise<NutModule>;
|
|
13
|
+
export declare function sleepMs(ms: number): Promise<void>;
|
|
14
|
+
export declare function screenSize(): Promise<{
|
|
15
|
+
width: number;
|
|
16
|
+
height: number;
|
|
17
|
+
}>;
|
|
18
|
+
export declare function mousePosition(): Promise<{
|
|
19
|
+
x: number;
|
|
20
|
+
y: number;
|
|
21
|
+
}>;
|
|
22
|
+
export declare function mouseSetPosition(x: number, y: number): Promise<void>;
|
|
23
|
+
export declare function mouseLeftClick(): Promise<void>;
|
|
24
|
+
export declare function mouseRightClick(): Promise<void>;
|
|
25
|
+
export declare function mouseMiddleClick(): Promise<void>;
|
|
26
|
+
export declare function mouseDoubleClick(): Promise<void>;
|
|
27
|
+
export declare function mousePressButton(button?: "left" | "right" | "middle"): Promise<void>;
|
|
28
|
+
export declare function mouseReleaseButton(button?: "left" | "right" | "middle"): Promise<void>;
|
|
29
|
+
export declare function mouseScrollDown(amount: number): Promise<void>;
|
|
30
|
+
export declare function mouseScrollUp(amount: number): Promise<void>;
|
|
31
|
+
export declare function mouseScrollLeft(amount: number): Promise<void>;
|
|
32
|
+
export declare function mouseScrollRight(amount: number): Promise<void>;
|
|
33
|
+
export declare function keyboardType(text: string): Promise<void>;
|
|
34
|
+
export declare function resolveNutKey(name: string): Promise<number>;
|
|
35
|
+
export declare function keyboardPressKey(name: string): Promise<void>;
|
|
36
|
+
export declare function keyboardPressCombo(keys: string[]): Promise<void>;
|
|
37
|
+
export declare function keyboardKeyDown(name: string): Promise<void>;
|
|
38
|
+
export declare function keyboardKeyUp(name: string): Promise<void>;
|
|
39
|
+
export declare function mouseDragPath(points: Point[]): Promise<void>;
|
|
40
|
+
export declare function captureScreenPng(dir: string, stem: string, region?: Box): Promise<string>;
|
|
41
|
+
export declare function pixelColorAt(x: number, y: number): Promise<{
|
|
42
|
+
r: number;
|
|
43
|
+
g: number;
|
|
44
|
+
b: number;
|
|
45
|
+
a: number;
|
|
46
|
+
}>;
|
|
47
|
+
export declare function findImageOnScreen(imagePath: string, opts?: FindImageOptions): Promise<{
|
|
48
|
+
left: number;
|
|
49
|
+
top: number;
|
|
50
|
+
width: number;
|
|
51
|
+
height: number;
|
|
52
|
+
} | null>;
|
|
53
|
+
export declare function findAllImagesOnScreen(imagePath: string, opts?: FindImageOptions): Promise<Array<{
|
|
54
|
+
left: number;
|
|
55
|
+
top: number;
|
|
56
|
+
width: number;
|
|
57
|
+
height: number;
|
|
58
|
+
}>>;
|
|
59
|
+
//# sourceMappingURL=backend.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"backend.d.ts","sourceRoot":"","sources":["../src/backend.ts"],"names":[],"mappings":"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"}
|