StrokesPlus.net
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
jay99995  
#1 Posted : Sunday, January 10, 2021 8:07:57 PM(UTC)
jay99995

Rank: Newbie

Reputation:

Groups: Approved
Joined: 7/5/2020(UTC)
Posts: 2
China

Thanks: 2 times
Was thanked: 1 time(s) in 1 post(s)
dear rob

I have set a hotkey F3 to run a script with a loop count, now I want to set F2 to stop the script, how should I write it,Looking forward to your reply, thank you very much!

for(var i=1;i<50;i++){
sp.MouseClick(new Point(740, 604), MouseButtons.Left, true, false); //按下左键
sp.MouseClick(new Point(740, 604), MouseButtons.Left, false, true); //松开左键
sp.Sleep(5000);

}
Rob  
#2 Posted : Monday, January 11, 2021 2:37:09 AM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 818
United States
Location: Tampa, FL

Thanks: 18 times
Was thanked: 195 time(s) in 170 post(s)
F3:
Updated mouse click to send down and up together, no need for two separate lines
Code:
sp.StoreBool("StopMouseLoop", false); //Set variable to false
for(var i=1;i<50;i++){
    if(sp.GetStoredBool("StopMouseLoop")) {
       break; //exit loop if value is true
    }
    sp.MouseClick(new Point(740, 604), MouseButtons.Left, true, true); //按下左键
    sp.Sleep(5000);
}

F2:
Code:
sp.StoreBool("StopMouseLoop", true); //set value to true so loop will exit
Rob  
#3 Posted : Monday, January 11, 2021 2:46:13 AM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 818
United States
Location: Tampa, FL

Thanks: 18 times
Was thanked: 195 time(s) in 170 post(s)
However, instead of a loop with a sleep call, I would recommend using a timer as it frees up the script engine to be used by something else and uses less CPU.

F3:
Code:
sp.StoreNumber("MouseLoopCount", 0);
sp.CreateTimer("MouseLoop", 
               0, 
               5000, 
               `if(sp.GetStoredNumber("MouseLoopCount") >= 50) {
                    sp.DeleteTimer("MouseLoop");
                } else {
                    sp.MouseClick(new Point(740, 604), MouseButtons.Left, true, true); //按下左键
                    sp.StoreNumber("MouseLoopCount",sp.GetStoredNumber("MouseLoopCount") + 1);
                }`
);

F2:
Code:
sp.DeleteTimer("MouseLoop");
thanks 1 user thanked Rob for this useful post.
jay99995 on 1/11/2021(UTC)
jay99995  
#4 Posted : Monday, January 11, 2021 9:08:25 PM(UTC)
jay99995

Rank: Newbie

Reputation:

Groups: Approved
Joined: 7/5/2020(UTC)
Posts: 2
China

Thanks: 2 times
Was thanked: 1 time(s) in 1 post(s)
dear rob,thank you very much!,you solved my problem perfectly。I have been using your software for many years,I will always support you。
thanks 1 user thanked jay99995 for this useful post.
Rob on 1/11/2021(UTC)
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.