当前位置:网站首页>Auto. JS to automatically authorize screen capture permission

Auto. JS to automatically authorize screen capture permission

2022-06-24 21:23:00 C colony

Write it at the front :

        This article records my own development process , Basic problems encountered , It is also convenient for future development .

        If you're a beginner Auto.js Development , I suggest you read this article Auto.js introduction 【 Hyperbasic 】, This article is the work I read when I started , Overall, I felt very good , The basic content has been mentioned , It is completely suitable for novices to make some simple scripts for their own use .

One 、 Developing documents

          This method is also mentioned in the development documentation , Some systems do not have the option to always allow , The subject also encountered this problem , Because the written script runs regularly , It is impossible to authorize manually by yourself , So I wrote an automatic authorization method , There are many deficiencies , I hope you can correct .

Two 、 Advanced method

1、 Define methods ( Personal recommendation only )

         I usually choose to open a new one js file , Store some convenient functions defined by myself separately , When developed in this way , I just need to copy the file to the folder , You can call all the functions defined by me .

2、 Code

function getScreenCapture(){
    let Thread = threads.start(function(){
        if(auto.service != null){  // If you have obtained accessibility 
                // Due to the different authorization texts between systems , Use regular expressions 
                let Allow = textMatches(/( allow | Start immediately | Unified )/).findOne(10*1000);
                if(Allow){
                    Allow.click();
                }
        }
    });
    if(!requestScreenCapture()){
        log(" Failed to request screenshot permission ");
        return false;
    }else{
        Thread.interrupt()
        log(" Obtained screenshot permission ");
        return true;
    }
}

          Here I mainly use Multithreading and Regular expressions To write this code , If you don't understand, you can read the development documents :Auto.js official API Document gate , Of course, some parts of the development documents are vague , If you are new to these two functions, you may not understand them , You can search some tutorials by yourself , You can also confide in me , Recommend .

3、 Calling method

var mydefine = require("MydefineFun.js");

         stay main.js Method can be used to receive the export , And then use mydefine You can call methods , among MydefineFun.js Is the file name where the method is written .

Four 、 Last

        1、 What's wrong , Welcome to discuss .

        2、 If you have any questions, please let me know , You can also pay attention to me , We will update other advanced methods later .

原网站

版权声明
本文为[C colony]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202211316377487.html