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,6 +317,8 @@ public class ScreenMatch
Tag = filename
};
if (!filename.StartsWith("no_"))
{
if (filename.StartsWith("binary_"))
{
templateImages.Add(ConvertToBinary(bitmap, thresholdConvertToBinary));
@ -327,6 +329,7 @@ public class ScreenMatch
}
}
}
}
// 캡쳐 및 템플릿 매칭 진행
public List<ScreenMatchResult> CaptureAndMatch()
@ -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

View File

@ -362,7 +362,7 @@ namespace WelsonJS.Service
List<ScreenMatchResult> 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)

3
app.js
View File

@ -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"),

View File

@ -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;

View File

@ -50,6 +50,18 @@ function AutoItObject() {
}
};
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;

View File

@ -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;