Update lib/autoit.js

This commit is contained in:
Namhyeon Go 2022-02-10 10:45:25 +09:00
parent 80947df3f8
commit 1ed11ef92c
4 changed files with 77 additions and 75 deletions

66
lib/autoit.js Normal file
View File

@ -0,0 +1,66 @@
////////////////////////////////////////////////////////////////////////
// AutoIt (AutoIt3, AutoItX) API
////////////////////////////////////////////////////////////////////////
function AutoIt_CreateObject = function() {
var obj = null;
try {
obj = CreateObject("AutoItX3.Control");
} catch (e) {
console.error("AutoIt_CreateObject() ->", e.message);
}
return obj;
}
function AutoIt_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;
}
function AutoItObject() {
this.interface = null;
this.create = function() {
this.interface = AutoIt_CreateObject();
};
this.execScript = function(scriptName) {
return AutoIt_execScript(scriptName);
};
this.callFunction = function(functionName, args) {
if (this.interface != null) {
try {
this.interface[functionName].apply(args);
} catch (e) {
console.error("AutoItObject.callFunction() ->", e.message);
}
} else {
console.warn("AutoItX is disabled");
}
};
this.create();
}
exports.create = function() {
return new AutoItObject();
};

View File

@ -1,22 +0,0 @@
////////////////////////////////////////////////////////////////////////
// AutoIt3 API
///////////////////////////////////////////////////////////////////////
var SHELL = require("lib/shell");
exports.VERSIONINFO = "AutoIt3 (autoit3.js) version 0.1";
exports.global = global;
exports.require = global.require;
exports.execScript = function(scriptName, args) {
var cmd = [
"%PROGRAMFILES(X86)%\\AutoIt3\\AutoIt3.exe",
scriptName + ".au3"
];
if (typeof(args) !== "undefined") {
cmd = cmd.concat(args);
}
return SHELL.exec(cmd);
};

View File

@ -1,26 +0,0 @@
////////////////////////////////////////////////////////////////////////
// AutoItX3.Control API
////////////////////////////////////////////////////////////////////////
var AutoItXObject = function() {
this.interface = null;
this.create = function() {
try {
this.interface = CreateObject("AutoItX3.Control");
return this;
} catch (e) {
console.error("AutoItXObject.create() ->", e.message);
}
};
this.getInterface = function() {
return this.interface;
};
this.create();
};
exports.create = function() {
return new AutoItXObject();
};

View File

@ -9,7 +9,7 @@ var SYS = require("lib/system");
var FILE = require("lib/file");
var HTTP = require("lib/http");
var Websocket = require("lib/websocket");
var AutoItX = require("lib/autoitx");
var AutoIt = require("lib/autoit");
// for remote debugging
var pageEventId = 0;
@ -54,26 +54,10 @@ var ChromeObject = function(interfaces) {
this.isPreventEvaluate = false;
this.create = function() {
try {
if (this.interfaces.indexOf("autoitx") > -1) {
this.oAutoIt = AutoItX.create().getInterface();
} else {
console.log("AutoItX is disabled");
}
} catch (e) {
console.log("AutoItX is disabled");
}
this.oAutoIt = AutoIt.create();
return this;
};
this.callAutoIt = function(FN, args) {
if (this.oAutoIt != null) {
this.oAutoIt[FN].apply(args);
} else {
console.log("AutoItX is disabled");
}
};
this.setIsPreventEvaluate = function(flag) {
this.isPreventEvaluate = flag;
};
@ -522,7 +506,7 @@ var ChromeObject = function(interfaces) {
this.terminate = function() {
try {
this.callAutoIt("WinKill", [this.getTitle()]);
AutoIt.callFunction("WinKill", [this.getTitle()]);
} catch (e) {
console.error("ChromeObject.terminate() ->", e.message);
}
@ -544,7 +528,7 @@ var ChromeObject = function(interfaces) {
// find window by title
var pageList = this.getPageList();
if (pageList.length > 0) {
this.callAutoIt("WinActivate", [title]);
AutoIt.callFunction("WinActivate", [title]);
}
} catch (e) {
console.error("ChromeObject._focus() ->", e.message);
@ -619,7 +603,7 @@ var ChromeObject = function(interfaces) {
var y = this.getRandomInt(0, bY);
var w = this.getRandomInt(bX * 3, sX - bX);
var h = this.getRandomInt(bY, sY - bY);
this.callAutoIt("WinMove", [title, "", x, y, w, h]);
AutoIt.callFunction("WinMove", [title, "", x, y, w, h]);
// blur
this.blur();
@ -635,7 +619,7 @@ var ChromeObject = function(interfaces) {
var h = this.getRandomInt(h1, h2);
var x = this.getRandomInt(0, (sX - w < 0 ? parseInt(sX * 0.2) : (sX - w)));
var y = this.getRandomInt(0, (sY - h < 0 ? parseInt(sY * 0.2) : (sY - h)));
this.callAutoIt("WinMove", [title, "", x, y, w, h]);
AutoIt.callFunction("WinMove", [title, "", x, y, w, h]);
// blur
this.blur();
@ -645,8 +629,8 @@ var ChromeObject = function(interfaces) {
if (this.debuggingPort > 0) {
try {
var pos = this.getScreenPosition();
this.callAutoIt("MouseMove" [pos.x + 100, pos.y + 100]);
this.callAutoIt("MouseWheel", ["down", times]);
AutoIt.callFunction("MouseMove" [pos.x + 100, pos.y + 100]);
AutoIt.callFunction("MouseWheel", ["down", times]);
} catch (e) {
console.error("ChromeObject.downMouseWheel() ->", e.message);
}
@ -657,8 +641,8 @@ var ChromeObject = function(interfaces) {
if (this.debuggingPort > 0) {
try {
var pos = this.getScreenPosition();
this.callAutoIt("MouseMove", [pos.x + 100, pos.y + 100]);
this.callAutoIt("MouseWheel", ["up", times]);
AutoIt.callFunction("MouseMove", [pos.x + 100, pos.y + 100]);
AutoIt.callFunction("MouseWheel", ["up", times]);
} catch (e) {
console.error("ChromeObject.upMouseWheel() ->", e.message);
}
@ -1085,7 +1069,7 @@ var ChromeObject = function(interfaces) {
};
this.sendSpaceKey = function() {
this.callAutoIt("Send", ["{SPACE}"]);
AutoIt.callFunction("Send", ["{SPACE}"]);
};
this.setValue = function(selector, value, repeat, searchIndex) {