-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautomation.js
89 lines (74 loc) · 3.09 KB
/
automation.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
const robot = require('robotjs');
const readline = require('readline');
// Create a readline interface for user input
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
// Prompt the user to input the total time in minutes
rl.question("Enter the total time for automation (in minutes): ", (input) => {
let time = parseFloat(input); // Convert input to a number
if (isNaN(time) || time <= 0) {
console.log("Invalid input. Please enter a positive number for time.");
rl.close();
return;
}
let duration = time * 60 * 1000; // Convert minutes to milliseconds
let startTime = Date.now();
console.log(`Automation will run for ${time} minutes.`);
// Function to randomly switch between 10 applications using Alt+Tab
function switchToRandomApplication() {
const randomSwitchCount = Math.floor(Math.random() * 10) + 1; // Randomly choose between 1 to 10 applications
console.log(`Switching to application #${randomSwitchCount} using Alt+Tab`);
// Simulate pressing Alt+Tab multiple times
robot.keyToggle('alt', 'down');
for (let i = 0; i < randomSwitchCount; i++) {
robot.keyTap('tab');
}
robot.keyToggle('alt', 'up');
}
// Function to simulate pressing Ctrl+Tab
function pressCtrlTab() {
console.log("Simulating Ctrl+Tab");
robot.keyTap('tab', 'control');
}
// Function to simulate scrolling up
function scrollUp() {
console.log("Simulating scroll up");
robot.scrollMouse(0, -3); // Scroll up by 3 steps (negative value)
}
// Function to simulate scrolling down
function scrollDown() {
console.log("Simulating scroll down");
robot.scrollMouse(0, 3); // Scroll down by 3 steps (positive value)
}
function runAutomation() {
// Randomly choose between actions to simulate variability
let randomAction = Math.random();
let action;
if (randomAction < 0.5) {
action = switchToRandomApplication; // 50% chance for Alt+Tab switching
} else if (randomAction < 0.7) {
action = pressCtrlTab; // 20% chance for Ctrl+Tab
} else if (randomAction < 0.85) {
action = scrollUp; // 15% chance for scrolling up
} else {
action = scrollDown; // 15% chance for scrolling down
}
action(); // Execute the selected action
// Slow down the random delay between actions (simulate human-like delays)
let delay = Math.random() * 15000 + 10000; // Random delay between 10 seconds and 25 seconds
console.log(`Next action in ${Math.round(delay / 1000)} seconds`);
// Recursively call the function after the delay
setTimeout(() => {
if (Date.now() - startTime < duration) {
runAutomation();
} else {
console.log(`Automation completed for ${time} minutes.`);
rl.close(); // Close the readline interface
}
}, delay);
}
// Start the automation process
runAutomation();
});