How to set AutoHotKey process priority & radom sleep?

大兔子大兔子 提交于 2019-12-14 03:03:01

问题


I want to set the high priority on the script below (only first).

Another important thing is whether you can do a Radom Sleep, 250 to 350??

Loop
{
    {
        ImageSearch,,, 0, 0, A_ScreenWidth, A_ScreenHeight, mor.png
        bT:= ErrorLevel ? bT : 1
        If bT
        {
            bT:= 0
            Random, x, 1130, 1300
            Random, y, 580, 680
            Click % x % % y %
                Sleep, 500

        }
    }

    ImageSearch,,, 0, 0, A_ScreenWidth, A_ScreenHeight, biz.png
    bT:= ErrorLevel ? bT : 1
    {
        bT:= 0
        Random, x, 540, 618
        Random, y, 419, 430
        Click % x % % y %

                 }
}
Return
f1:: ExitApp

回答1:


Try it this way:

Process, Priority,, High 

Loop
{
    If GetKeyState("F1","P")
        ExitApp
    ImageSearch,,, 0, 0, A_ScreenWidth, A_ScreenHeight, mor.png
    bT:= ErrorLevel ? bT : 1
    If bT
    {
        bT:= 0
        Random, x, 1130, 1300
        Random, y, 580, 680
        Click %x%, %y%
        Sleep, % rnd(250,350)   
    }
    ImageSearch,,, 0, 0, A_ScreenWidth, A_ScreenHeight, biz.png
    bT:= ErrorLevel ? bT : 1
    If bT
    {
        bT:= 0
        Random, x, 540, 618
        Random, y, 419, 430
        Click %x%, %y%
    }   
}

rnd(min,max){
    Random, myVar,% min,% max
    return myVar
}

Untested.




回答2:


If you want to change the priority of the thread the script is running on so that it can/cannot be interrupted by another thread, you use the Thread command:

Thread, Priority, Level

Where Level is a signed 32 bit integer. See AHK — Thread.

You can generate a pseudo-random number using the Randomcommand (as you already are in your code). If you want to pause the thread using random numbers, you do it like so:

Random, timer, 250, 350    ; Generates the pseudo-random number
Sleep, %timer%               ; Pauses script execution according to value


来源:https://stackoverflow.com/questions/54533030/how-to-set-autohotkey-process-priority-radom-sleep

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!