diff --git a/WelsonJS.Toolkit/WelsonJS.Service/ScreenMatch.cs b/WelsonJS.Toolkit/WelsonJS.Service/ScreenMatch.cs index 0e39063..34b015f 100644 --- a/WelsonJS.Toolkit/WelsonJS.Service/ScreenMatch.cs +++ b/WelsonJS.Toolkit/WelsonJS.Service/ScreenMatch.cs @@ -317,13 +317,16 @@ public class ScreenMatch Tag = filename }; - if (filename.StartsWith("binary_")) + if (!filename.StartsWith("no_")) { - templateImages.Add(ConvertToBinary(bitmap, thresholdConvertToBinary)); - } - else - { - templateImages.Add(bitmap); + if (filename.StartsWith("binary_")) + { + templateImages.Add(ConvertToBinary(bitmap, thresholdConvertToBinary)); + } + else + { + templateImages.Add(bitmap); + } } } } @@ -382,6 +385,8 @@ public class ScreenMatch Bitmap image = templateImages[templateCurrentIndex]; string templateName = image.Tag as string; + string nextTemplateName = parent.GetNextTemplateName(); + Size templateSize = new Size { Width = image.Width, @@ -390,6 +395,12 @@ public class ScreenMatch parent.Log($"Trying match the template {templateName} on the screen {i}..."); + if (!String.IsNullOrEmpty(nextTemplateName) && templateName != nextTemplateName) + { + parent.Log($"Ignored the template {templateName}"); + break; + } + Bitmap _mainImage; if (templateName.StartsWith("binary_")) { @@ -496,6 +507,7 @@ public class ScreenMatch // if use Clipboard if (sampleClipboard.Contains(templateName)) { + parent.Log($"Trying to use the clipboard... {templateName}"); Thread th = new Thread(new ThreadStart(() => { try diff --git a/WelsonJS.Toolkit/WelsonJS.Service/ServiceMain.cs b/WelsonJS.Toolkit/WelsonJS.Service/ServiceMain.cs index 5ecc822..e1ac839 100644 --- a/WelsonJS.Toolkit/WelsonJS.Service/ServiceMain.cs +++ b/WelsonJS.Toolkit/WelsonJS.Service/ServiceMain.cs @@ -362,7 +362,7 @@ namespace WelsonJS.Service List matchedResults = screenMatcher.CaptureAndMatch(); matchedResults.ForEach(result => { - Log(DispatchServiceEvent("screenTime", new string[] + Log(DispatchServiceEvent("screenTemplateMatched", new string[] { result.FileName, result.ScreenNumber.ToString(), @@ -425,6 +425,22 @@ namespace WelsonJS.Service return arguments; } + public string GetNextTemplateName() + { + string templateName = string.Empty; + + try + { + templateName = DispatchServiceEvent("screenNextTemplate"); + } + catch (Exception ex) + { + Log($"Use all templates because of {ex.Message}"); + } + + return templateName; + } + public string DispatchServiceEvent(string eventType, string[] args = null) { if (args == null) diff --git a/app.js b/app.js index e04056a..baca85b 100644 --- a/app.js +++ b/app.js @@ -626,7 +626,8 @@ function dispatchServiceEvent(name, eventType, w_args, argl) { start: bind("ServiceStart"), stop: bind("ServiceStop"), elapsedTime: bind("ServiceElapsedTime"), - screenTime: bind("ServiceScreenTime"), + screenNextTemplate: bind("ScreenNextTemplate"), + screenTemplateMatched: bind("ScreenTemplateMatched"), fileCreated: bind("FileCreated"), networkConnected: bind("NetworkConnected"), registryModified: bind("RegistryModified"), diff --git a/defaultService.example.js b/defaultService.example.js index b4118ea..9fe01f1 100644 --- a/defaultService.example.js +++ b/defaultService.example.js @@ -26,8 +26,12 @@ function onMessageReceived() { return "onMessageReceived recevied. " + args.join(', '); } -function onServiceScreenTime(args) { - return "onServiceScreenTime recevied. " + args.join(', '); +function onScreenNextTemplate(args) { + return "example.png"; +} + +function onScreenTemplateMatched(args) { + return "onScreenTemplateMatched recevied. " + args.join(', '); } function onFileCreated(args) { @@ -51,7 +55,8 @@ exports.getDeviceID = getDeviceID; exports.onServiceStart = onServiceStart; exports.onServiceStop = onServiceStop; exports.onServiceElapsedTime = onServiceElapsedTime; -exports.onServiceScreenTime = onServiceScreenTime; +exports.onScreenNextTemplate = onScreenNextTemplate; +exports.onScreenTemplateMatched = onScreenTemplateMatched; exports.onFileCreated = onFileCreated; exports.onNetworkConnected = onNetworkConnected; exports.onRegistryModified = onRegistryModified; diff --git a/lib/autoit.js b/lib/autoit.js index 82122bf..b384fe3 100644 --- a/lib/autoit.js +++ b/lib/autoit.js @@ -49,6 +49,18 @@ function AutoItObject() { console.warn("AutoItX is disabled"); } }; + + this.mouseMove = function(x ,y) { + this.callFunction("MouseMove", [x, y]); + }; + + this.mouseClick = function(_button) { + this.callFunction("MouseClick", [_button]); + }; + + this.send = function(keys) { + this.callFunction("Send", [keys]); + }; this.create(); } @@ -57,6 +69,6 @@ exports.create = function() { return new AutoItObject(); }; -exports.VERSIONINFO = "AutoIt API interface version 0.1.3"; +exports.VERSIONINFO = "AutoItX API interface version 0.1.4"; exports.global = global; exports.require = global.require; diff --git a/lib/chrome.js b/lib/chrome.js index 0ebfc8a..bf28f17 100644 --- a/lib/chrome.js +++ b/lib/chrome.js @@ -671,7 +671,7 @@ var ChromeObject = function() { if (this.debuggingPort > 0) { try { var pos = this.getScreenPosition(); - this.oAutoIt.callFunction("MouseMove" [pos.x + 100, pos.y + 100]); + this.mouseMove(pos.x + 100, pos.y + 100); this.oAutoIt.callFunction("MouseWheel", ["down", times]); } catch (e) { console.error("ChromeObject.downMouseWheel() ->", e.message); @@ -683,7 +683,7 @@ var ChromeObject = function() { if (this.debuggingPort > 0) { try { var pos = this.getScreenPosition(); - this.oAutoIt.callFunction("MouseMove", [pos.x + 100, pos.y + 100]); + this.mouseMove(pos.x + 100, pos.y + 100); this.oAutoIt.callFunction("MouseWheel", ["up", times]); } catch (e) { console.error("ChromeObject.upMouseWheel() ->", e.message); @@ -1144,11 +1144,11 @@ var ChromeObject = function() { }; this.sendKeys = function(s) { - this.oAutoIt.callFunction("Send", [s]); + this.oAutoIt.send(s); }; this.sendSpaceKey = function() { - this.oAutoIt.callFunction("Send", ["{SPACE}"]); + this.oAutoIt.send("{SPACE}"); }; this.setValue = function(selector, value, repeat, searchIndex) { @@ -1314,8 +1314,8 @@ var ChromeObject = function() { this.mouseClick = function(x, y) { var screenPosition = this.getScreenPosition(); - this.oAutoIt.callFunction("MouseMove", [screenPosition.x + this.baseScreenX + x, screenPosition.y + this.baseScreenY + y]); - this.oAutoIt.callFunction("MouseClick", ["left"]); + this.oAutoIt.mouseMove(screenPosition.x + this.baseScreenX + x, screenPosition.y + this.baseScreenY + y); + this.oAutoIt.mouseClick("left"); }; this.mouseWheelUp = function() { @@ -1423,7 +1423,7 @@ exports.startDebugInPrivate = function(url, proxy, profileName, debuggingPort, i ; }; -exports.VERSIONINFO = "Chrome Web Browser Debugging Interface (chrome.js) version 0.4.14"; +exports.VERSIONINFO = "Chrome Web Browser Debugging Interface (chrome.js) version 0.4.15"; exports.AUTHOR = "abuse@catswords.net"; exports.global = global; exports.require = global.require;