Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
663 views
in Technique[技术] by (71.8m points)

loops - Logitech Lua Scripting and Looping

I'm having a little problem with my script here using a Logitech mouse. I will be using it for farming in a game.

function OnEvent(event, arg)
   if event == "MOUSE_BUTTON_PRESSED" and arg == 5 then
    for i = 0, 300 do
            PressAndReleaseKey("f9")
            Sleep(400)
            PressAndReleaseKey("enter")
            Sleep(600)
            PressAndReleaseKey("f5")
            Sleep(50)
            PressMouseButton(1)
            Sleep(50)
            ReleaseMouseButton(1)
    end
            PressAndReleaseKey("1")
    repeat
    until IsMouseButtonPressed(3)
   end
end

So it will loop for 300 times and then press 1 when it's done, then repeat the loop again for 300 times, so on & so on. Problem I'm facing is, when I'm trying to abort the script, it will first finish the for-loop before being stopped by using Right-click button(IsMouseButtonPressed(3)), which is really hard to time (300x is a lot)

How can I pause/stop it during the for-loop, would it be possible?

question from:https://stackoverflow.com/questions/65599134/logitech-lua-scripting-and-looping

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Frequently check if the button is pressed and break the loop.

Break up those long blocking Sleeps.

Instead of Sleep(400) consider doing something like

for i = 1, 400, 50 do
  Sleep(50)
  if IsMouseButtonPressed(3) then break end
end

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...