add screen capture and color searching
This commit is contained in:
@@ -13,7 +13,7 @@ module.exports = function(__runtime__, scope){
|
||||
}
|
||||
|
||||
automator.click = function(){
|
||||
if(arguments.length >= 2 && typeof(arguments[0]) == 'number' && typeof(arguments[1]) == 'number'){
|
||||
if(arguments.length == 2 && typeof(arguments[0]) == 'number' && typeof(arguments[1]) == 'number'){
|
||||
return __runtime__.automator.click(arguments[0], arguments[1]);
|
||||
}
|
||||
return performAction(function(target){
|
||||
@@ -34,7 +34,7 @@ module.exports = function(__runtime__, scope){
|
||||
automator.gesture = __runtime__.automator.gesture.bind(__runtime__.automator, 0);
|
||||
automator.gestureAsync = __runtime__.automator.gestureAsync.bind(__runtime__.automator, 0);
|
||||
automator.swipe = __runtime__.automator.swipe.bind(__runtime__.automator);
|
||||
automator.gestures = function(){
|
||||
automator.gestures = function(){
|
||||
return __runtime__.automator.gestures(toStrokes(arguments));
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,11 @@ module.exports = function(__runtime__, scope){
|
||||
__runtime__.toast(text);
|
||||
}
|
||||
|
||||
scope.toastLog = function(text){
|
||||
__runtime__.toast(text);
|
||||
scope.log(text);
|
||||
}
|
||||
|
||||
scope.sleep = function(millis){
|
||||
__runtime__.sleep(millis);
|
||||
}
|
||||
|
||||
64
autojs/src/main/assets/modules/__images__.js
Normal file
64
autojs/src/main/assets/modules/__images__.js
Normal file
@@ -0,0 +1,64 @@
|
||||
|
||||
module.exports = function(__runtime__, scope){
|
||||
var images = {};
|
||||
|
||||
var colorFinder = __runtime__.images.colorFinder;
|
||||
|
||||
images.requestScreenCapture = __runtime__.images.requestScreenCapture.bind(__runtime__.images);
|
||||
|
||||
images.captureScreen = __runtime__.images.captureScreen.bind(__runtime__.images);
|
||||
|
||||
images.saveImage = __runtime__.images.saveImage.bind(__runtime__.images);
|
||||
|
||||
images.findColor = function(img, color, options){
|
||||
options = options || {};
|
||||
var region = options.region || [];
|
||||
x = region[0] || 0;
|
||||
y = region[1] || 0;
|
||||
width = region[2] || (img.getWidth() - x);
|
||||
height = region[3] || (img.getHeight() - y);
|
||||
threads = options.threads || 4;
|
||||
if(options.threshold !== 0){
|
||||
threshold = options.threshold || 8;
|
||||
}
|
||||
algorithm = options.algorithm || "rgb";
|
||||
var rect = new android.graphics.Rect(x, y, width + x, height + y);
|
||||
var colorDetector = getColorDetector(color, algorithm, threshold);
|
||||
return colorFinder.findColorConcurrently(img, colorDetector, rect, threads);
|
||||
}
|
||||
|
||||
images.findColorInRegion = function(img, color, x, y, width, height, threads, algorithm, threshold){
|
||||
return findColor(img, color, {
|
||||
region: [x, y, width, height],
|
||||
algorithm: algorithm,
|
||||
threshold: threshold,
|
||||
threads: threads
|
||||
});
|
||||
}
|
||||
|
||||
images.findColorEquals = function(img, color, x, y, width, height, threads){
|
||||
return findColor(img, color, {
|
||||
region: [x, y, width, height],
|
||||
algorithm: "equal",
|
||||
threads: threads
|
||||
});
|
||||
}
|
||||
|
||||
function getColorDetector(color, algorithm, threshold){
|
||||
switch(algorithm){
|
||||
case "rgb":
|
||||
return new com.stardust.autojs.runtime.api.image.ColorDetector.RGBDistanceDetector(color, threshold);
|
||||
case "equal":
|
||||
return new com.stardust.autojs.runtime.api.image.ColorDetector.EqualityDetector(color);
|
||||
case "rgb+":
|
||||
return new com.stardust.autojs.runtime.api.image.ColorDetector.WeightedRGBDistanceDetector(color, threshold);
|
||||
case "hs":
|
||||
return new com.stardust.autojs.runtime.api.image.ColorDetector.HSDistanceDetector(color, threshold);
|
||||
}
|
||||
throw new Error("Unknown algorithm: " + algorithm);
|
||||
}
|
||||
|
||||
scope.__asGlobal__(images, ['requestScreenCapture', 'captureScreen', 'findColor', 'findColorInRegion', 'findColorEquals']);
|
||||
|
||||
return images;
|
||||
}
|
||||
@@ -9,20 +9,7 @@ module.exports = function(__runtime__, scope){
|
||||
scope[method] = (function(method) {
|
||||
return function(){
|
||||
var s = selector();
|
||||
//这里不知道怎么写。尴尬。只能写成这样。
|
||||
if(arguments.length == 0){
|
||||
return s[method]();
|
||||
}else if(arguments.length == 1){
|
||||
return s[method](arguments[0]);
|
||||
}else if(arguments.length == 2){
|
||||
return s[method](arguments[0], arguments[1]);
|
||||
}else if(arguments.length == 3){
|
||||
return s[method](arguments[0], arguments[1], arguments[2]);
|
||||
}else if(arguments.length == 4){
|
||||
return s[method](arguments[0], arguments[1], arguments[2], arguments[3]);
|
||||
}else{
|
||||
return s[method].call(s, Array.prototype.slice.call(arguments));
|
||||
}
|
||||
return s[method].apply(s, Array.prototype.slice.call(arguments));
|
||||
};
|
||||
})(method);
|
||||
}
|
||||
@@ -33,4 +20,3 @@ module.exports = function(__runtime__, scope){
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user