welsonjs/lib/autoit.js

58 lines
1.6 KiB
JavaScript
Raw Normal View History

2022-02-10 01:45:25 +00:00
////////////////////////////////////////////////////////////////////////
// AutoIt (AutoIt3, AutoItX) API
////////////////////////////////////////////////////////////////////////
function AutoItObject() {
this.interface = null;
this.create = function() {
try {
this.interface = CreateObject("AutoItX3.Control");
} catch (e) {
console.error("AutoIt_CreateObject() ->", e.message);
}
2022-02-10 01:45:25 +00:00
};
this.execScript = function(scriptName) {
var result = null;
var cmd = [
"%PROGRAMFILES(X86)%\\AutoIt3\\AutoIt3.exe",
scriptName + ".au3"
];
if (typeof args !== "undefined") {
cmd = cmd.concat(args);
}
try {
result = SHELL.exec(cmd);
} catch (e) {
console.error("AutoIt_execScript() ->", e.message);
}
return result;
2022-02-10 01:45:25 +00:00
};
this.callFunction = function(functionName, args) {
console.log("Calling AutoItX function...", functionName);
2022-02-10 01:45:25 +00:00
if (this.interface != null) {
try {
//this.interface[functionName].apply(null, args);
eval("this.interface." + functionName + "(\"" + args.map(addslashes).join("\", \"") + "\")");
2022-02-10 08:22:35 +00:00
sleep(300);
} catch (e) {
console.error("AutoItObject.callFunction() ->", e.message);
}
2022-02-10 01:45:25 +00:00
} else {
console.warn("AutoItX is disabled");
}
};
this.create();
2022-02-10 01:45:25 +00:00
}
exports.create = function() {
return new AutoItObject();
};