Search code examples
processautohotkeysleep

How to set AutoHotKey process priority & radom sleep?


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

Solution

  • 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.