Update ScreenMatch.cs and related files
Some checks failed
CodeQL / Analyze (csharp) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled

This commit is contained in:
Namhyeon Go 2024-09-20 16:53:50 +09:00
parent 855cf6adef
commit e7f65d50b0
6 changed files with 65 additions and 19 deletions

View File

@ -317,13 +317,16 @@ public class ScreenMatch
Tag = filename Tag = filename
}; };
if (filename.StartsWith("binary_")) if (!filename.StartsWith("no_"))
{ {
templateImages.Add(ConvertToBinary(bitmap, thresholdConvertToBinary)); if (filename.StartsWith("binary_"))
} {
else templateImages.Add(ConvertToBinary(bitmap, thresholdConvertToBinary));
{ }
templateImages.Add(bitmap); else
{
templateImages.Add(bitmap);
}
} }
} }
} }
@ -382,6 +385,8 @@ public class ScreenMatch
Bitmap image = templateImages[templateCurrentIndex]; Bitmap image = templateImages[templateCurrentIndex];
string templateName = image.Tag as string; string templateName = image.Tag as string;
string nextTemplateName = parent.GetNextTemplateName();
Size templateSize = new Size Size templateSize = new Size
{ {
Width = image.Width, Width = image.Width,
@ -390,6 +395,12 @@ public class ScreenMatch
parent.Log($"Trying match the template {templateName} on the screen {i}..."); 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; Bitmap _mainImage;
if (templateName.StartsWith("binary_")) if (templateName.StartsWith("binary_"))
{ {
@ -496,6 +507,7 @@ public class ScreenMatch
// if use Clipboard // if use Clipboard
if (sampleClipboard.Contains(templateName)) if (sampleClipboard.Contains(templateName))
{ {
parent.Log($"Trying to use the clipboard... {templateName}");
Thread th = new Thread(new ThreadStart(() => Thread th = new Thread(new ThreadStart(() =>
{ {
try try

View File

@ -362,7 +362,7 @@ namespace WelsonJS.Service
List<ScreenMatchResult> matchedResults = screenMatcher.CaptureAndMatch(); List<ScreenMatchResult> matchedResults = screenMatcher.CaptureAndMatch();
matchedResults.ForEach(result => matchedResults.ForEach(result =>
{ {
Log(DispatchServiceEvent("screenTime", new string[] Log(DispatchServiceEvent("screenTemplateMatched", new string[]
{ {
result.FileName, result.FileName,
result.ScreenNumber.ToString(), result.ScreenNumber.ToString(),
@ -425,6 +425,22 @@ namespace WelsonJS.Service
return arguments; 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) public string DispatchServiceEvent(string eventType, string[] args = null)
{ {
if (args == null) if (args == null)

3
app.js
View File

@ -626,7 +626,8 @@ function dispatchServiceEvent(name, eventType, w_args, argl) {
start: bind("ServiceStart"), start: bind("ServiceStart"),
stop: bind("ServiceStop"), stop: bind("ServiceStop"),
elapsedTime: bind("ServiceElapsedTime"), elapsedTime: bind("ServiceElapsedTime"),
screenTime: bind("ServiceScreenTime"), screenNextTemplate: bind("ScreenNextTemplate"),
screenTemplateMatched: bind("ScreenTemplateMatched"),
fileCreated: bind("FileCreated"), fileCreated: bind("FileCreated"),
networkConnected: bind("NetworkConnected"), networkConnected: bind("NetworkConnected"),
registryModified: bind("RegistryModified"), registryModified: bind("RegistryModified"),

View File

@ -26,8 +26,12 @@ function onMessageReceived() {
return "onMessageReceived recevied. " + args.join(', '); return "onMessageReceived recevied. " + args.join(', ');
} }
function onServiceScreenTime(args) { function onScreenNextTemplate(args) {
return "onServiceScreenTime recevied. " + args.join(', '); return "example.png";
}
function onScreenTemplateMatched(args) {
return "onScreenTemplateMatched recevied. " + args.join(', ');
} }
function onFileCreated(args) { function onFileCreated(args) {
@ -51,7 +55,8 @@ exports.getDeviceID = getDeviceID;
exports.onServiceStart = onServiceStart; exports.onServiceStart = onServiceStart;
exports.onServiceStop = onServiceStop; exports.onServiceStop = onServiceStop;
exports.onServiceElapsedTime = onServiceElapsedTime; exports.onServiceElapsedTime = onServiceElapsedTime;
exports.onServiceScreenTime = onServiceScreenTime; exports.onScreenNextTemplate = onScreenNextTemplate;
exports.onScreenTemplateMatched = onScreenTemplateMatched;
exports.onFileCreated = onFileCreated; exports.onFileCreated = onFileCreated;
exports.onNetworkConnected = onNetworkConnected; exports.onNetworkConnected = onNetworkConnected;
exports.onRegistryModified = onRegistryModified; exports.onRegistryModified = onRegistryModified;

View File

@ -49,6 +49,18 @@ function AutoItObject() {
console.warn("AutoItX is disabled"); 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(); this.create();
} }
@ -57,6 +69,6 @@ exports.create = function() {
return new AutoItObject(); 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.global = global;
exports.require = global.require; exports.require = global.require;

View File

@ -671,7 +671,7 @@ var ChromeObject = function() {
if (this.debuggingPort > 0) { if (this.debuggingPort > 0) {
try { try {
var pos = this.getScreenPosition(); 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]); this.oAutoIt.callFunction("MouseWheel", ["down", times]);
} catch (e) { } catch (e) {
console.error("ChromeObject.downMouseWheel() ->", e.message); console.error("ChromeObject.downMouseWheel() ->", e.message);
@ -683,7 +683,7 @@ var ChromeObject = function() {
if (this.debuggingPort > 0) { if (this.debuggingPort > 0) {
try { try {
var pos = this.getScreenPosition(); 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]); this.oAutoIt.callFunction("MouseWheel", ["up", times]);
} catch (e) { } catch (e) {
console.error("ChromeObject.upMouseWheel() ->", e.message); console.error("ChromeObject.upMouseWheel() ->", e.message);
@ -1144,11 +1144,11 @@ var ChromeObject = function() {
}; };
this.sendKeys = function(s) { this.sendKeys = function(s) {
this.oAutoIt.callFunction("Send", [s]); this.oAutoIt.send(s);
}; };
this.sendSpaceKey = function() { this.sendSpaceKey = function() {
this.oAutoIt.callFunction("Send", ["{SPACE}"]); this.oAutoIt.send("{SPACE}");
}; };
this.setValue = function(selector, value, repeat, searchIndex) { this.setValue = function(selector, value, repeat, searchIndex) {
@ -1314,8 +1314,8 @@ var ChromeObject = function() {
this.mouseClick = function(x, y) { this.mouseClick = function(x, y) {
var screenPosition = this.getScreenPosition(); var screenPosition = this.getScreenPosition();
this.oAutoIt.callFunction("MouseMove", [screenPosition.x + this.baseScreenX + x, screenPosition.y + this.baseScreenY + y]); this.oAutoIt.mouseMove(screenPosition.x + this.baseScreenX + x, screenPosition.y + this.baseScreenY + y);
this.oAutoIt.callFunction("MouseClick", ["left"]); this.oAutoIt.mouseClick("left");
}; };
this.mouseWheelUp = function() { 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.AUTHOR = "abuse@catswords.net";
exports.global = global; exports.global = global;
exports.require = global.require; exports.require = global.require;