Rank: Newbie
Groups: Approved
Joined: 7/5/2020(UTC) Posts: 2 Thanks: 3 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);
}
|
|
|
|
Rank: Administration
Groups: Translators, Members, Administrators Joined: 1/11/2018(UTC) Posts: 1,359 Location: Tampa, FL Thanks: 28 times Was thanked: 419 time(s) in 356 post(s)
|
F3:Updated mouse click to send down and up together, no need for two separate linesCode: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
|
|
|
|
Rank: Administration
Groups: Translators, Members, Administrators Joined: 1/11/2018(UTC) Posts: 1,359 Location: Tampa, FL Thanks: 28 times Was thanked: 419 time(s) in 356 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");
|
1 user thanked Rob for this useful post.
|
|
|
Rank: Newbie
Groups: Approved
Joined: 7/5/2020(UTC) Posts: 2 Thanks: 3 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。
|
1 user thanked jay99995 for this useful post.
|
|
|
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.
Important Information:
The StrokesPlus.net Forum uses cookies. By continuing to browse this site, you are agreeing to our use of cookies.
More Details
Close