-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from rubickCenter/feature/new
♻️ 修改 simulation 实现方式,添加单测.
- Loading branch information
Showing
15 changed files
with
2,621 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
|
||
### Node ### | ||
# Logs | ||
.idea | ||
logs | ||
*.log | ||
npm-debug.log* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import test from 'ava'; | ||
import { getClipboardContent, ClipboardContent } from '../src' | ||
|
||
test('get clipboard content', (t) => { | ||
const result: ClipboardContent = getClipboardContent() | ||
t.true((result.type === 'text' && typeof result.content === 'string') || (result.type === 'file' && typeof result.content === 'object') || result.type === null) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import test from 'ava'; | ||
import { keyboard, Key, mouse, left, right, up, down } from '../src' | ||
|
||
test('simulateKeyboardTap one key', (t) => { | ||
t.notThrows(async () => await keyboard.type('a')) | ||
}); | ||
|
||
test('simulateKeyboardTap multi key', (t) => { | ||
t.notThrows(async () => await keyboard.type('calculator')) | ||
}); | ||
|
||
test('simulateKeyboardTap key with modifier', (t) => { | ||
t.notThrows(async () => await keyboard.type(Key.LeftControl, Key.LeftSuper, Key.A)) | ||
}); | ||
|
||
test('mouse move', (t) => { | ||
t.notThrows(async () => await mouse.move(left(100))) | ||
t.notThrows(async () => await mouse.move(up(50))) | ||
t.notThrows(async () => await mouse.move(right(100))) | ||
t.notThrows(async () => await mouse.move(down(50))) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. | ||
# yarn lockfile v1 | ||
|
||
|
||
"@napi-rs/cli@^2.16.3": | ||
version "2.16.3" | ||
resolved "https://registry.npmmirror.com/@napi-rs/cli/-/cli-2.16.3.tgz#6943d0614bbb4900a97b18ae074f735864f78c4b" | ||
integrity sha512-3mLNPlbbOhpbIUKicLrJtIearlHXUuXL3UeueYyRRplpVMNkdn8xCyzY6PcYZi3JXR8bmCOiWgkVmLnrSL7DKw== |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module.exports = { | ||
extensions: ['ts'], | ||
workerThreads: false, | ||
require: ['@swc-node/register'], | ||
files: ['__test__/**/*.spec.ts'], | ||
timeout: '3m', | ||
environmentVariables: { | ||
TS_NODE_PROJECT: './tsconfig.test.json', | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,6 @@ | ||
import { | ||
Position, | ||
sendKeyboardSimulation as ks, | ||
sendMouseSimulation as ms, | ||
} from "../addon"; | ||
import { keyboard, Key, mouse, left, right, up, down, straightTo } from "@nut-tree/nut-js"; | ||
|
||
export type MouseBtn = | ||
| "Left" | ||
| "Middle" | ||
| "Right" | ||
| "Back" | ||
| "Forward" | ||
keyboard.config.autoDelayMs = 10; | ||
mouse.config.autoDelayMs = 10; | ||
|
||
export interface MoveMoveInput { | ||
type: "relative" | "absolute"; | ||
data: Position; | ||
} | ||
|
||
// example: {+CTRL}a{-CTRL}{+SHIFT}Hello World{-SHIFT} | ||
// 所有可用键 https://github.com/enigo-rs/enigo/blob/master/src/keycodes.rs | ||
export const sendKeyboardSimulation = (cmd: string) => ks(cmd); | ||
|
||
export const mouseScrollX = (len: number) => { | ||
ms({ action: 3, data: { x: len, y: 0 } }); | ||
} | ||
|
||
export const mouseScrollY = (len: number) => { | ||
ms({ action: 4, data: { x: 0, y: len } }); | ||
}; | ||
|
||
export const mouseMove = (input: MoveMoveInput) => { | ||
ms({ action: input.type === "absolute" ? 2 : 1, data: input.data }); | ||
}; | ||
|
||
export const mouseLocaion = () => ms({ action: 0 }) | ||
|
||
const mouseDUC = (btn: MouseBtn, action: 5 | 6 | 7) => { | ||
let button = 0; | ||
switch (btn) { | ||
case "Left": | ||
break; | ||
case "Middle": | ||
button = 1; | ||
break; | ||
case "Right": | ||
button = 2; | ||
break; | ||
case "Back": | ||
button = 3; | ||
break; | ||
case "Forward": | ||
button = 4; | ||
break; | ||
default: | ||
break; | ||
} | ||
ms({ action, button }); | ||
}; | ||
|
||
export const mouseDown = (btn: MouseBtn) => mouseDUC(btn, 6) | ||
export const mouseUp = (btn: MouseBtn) => mouseDUC(btn, 5) | ||
export const mouseClick = (btn: MouseBtn) => mouseDUC(btn, 7) | ||
export { keyboard, mouse, Key, left, right, up, down, straightTo} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,34 @@ | ||
{ | ||
"compilerOptions": { | ||
"outDir": "dist", | ||
"allowSyntheticDefaultImports": true, | ||
"declaration": true, | ||
"downlevelIteration": true, | ||
"emitDecoratorMetadata": true, | ||
"experimentalDecorators": true, | ||
"importHelpers": false, | ||
"module": "CommonJS", | ||
"moduleResolution": "node", | ||
"newLine": "LF", | ||
"noEmitHelpers": true, | ||
"noUnusedLocals": true, | ||
"noUnusedParameters": true, | ||
"removeComments": true, | ||
"strict": true, | ||
"skipLibCheck": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"target": "ES2018", | ||
"inlineSourceMap": true, | ||
"esModuleInterop": true, | ||
"module": "ESNext", | ||
"moduleResolution": "Node", | ||
"target": "ESNext", | ||
"lib": [ | ||
"ESNext", | ||
"DOM" | ||
] | ||
"stripInternal": true, | ||
"importsNotUsedAsValues": "remove", | ||
"paths": { | ||
"@node-rs/*": ["./addon"] | ||
}, | ||
"outDir": "dist", | ||
"lib": ["dom", "ES5", "ES2015", "ES2016", "ES2017", "ES2018", "ES2019", "ES2020", "esnext"] | ||
}, | ||
"include": [ | ||
"./src/**/*" | ||
] | ||
"./src/**/*", | ||
], | ||
"exclude": ["node_modules", "addon"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"include": [ | ||
"__test__", | ||
"./src/**/*" | ||
] | ||
} |
Oops, something went wrong.