-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest-mouse.js
75 lines (68 loc) · 2.3 KB
/
test-mouse.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
const readline = require('readline');
const adb = require('adbkit');
const client = adb.createClient();
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
// Function to execute ADB shell commands
async function executeADBShellCommand(command) {
const device = await client.listDevices();
if (!device || device.length === 0) {
console.error('No connected Android device found.');
return;
}
const deviceId = device[0].id;
client.shell(deviceId, command);
}
// Function to perform mouse movement
async function performMouseMovement(dx, dy) {
const command = `input touchscreen swipe 0 0 ${dx} ${dy}`;
await executeADBShellCommand(command);
}
// Function to perform primary click (tap) event
async function performPrimaryClick() {
const command = 'input tap';
await executeADBShellCommand(command);
}
// Function to process keyboard input
function processKeyboardInput(input) {
switch (input) {
case 'up':
performMouseMovement(0, -100); // Move mouse up
break;
case 'down':
performMouseMovement(0, 100); // Move mouse down
break;
case 'left':
performMouseMovement(-100, 0); // Move mouse left
break;
case 'right':
performMouseMovement(100, 0); // Move mouse right
break;
case 'enter':
performPrimaryClick(); // Perform primary click (tap)
break;
case 'exit':
rl.close();
break;
default:
console.log('Invalid input! Use arrow keys for mouse movement, press "Enter" to perform primary click, or press "Exit" to quit.');
break;
}
}
// Start listening to keyboard input
console.log('Use arrow keys for mouse movement, press "Enter" to perform primary click, or press "Exit" to quit.');
rl.input.on('keypress', (_, key) => {
if (key) {
if (key.name === 'up' || key.name === 'down' || key.name === 'left' || key.name === 'right') {
processKeyboardInput(key.name);
} else if (key.name === 'return') {
processKeyboardInput('enter');
} else if (key.name === 'escape') {
processKeyboardInput('exit');
}
}
});
rl.input.setRawMode(true);
rl.input.resume();