脚本不仅停止键盘

Script do not stop only Keyboard

大家好,我有一个键盘 G105
我试图制作一个小脚本,正在运行,但它不想停止。
我想打开 G1,关闭 G2。谢谢



**Macro LIST**

  

     skill Selfbuff -- use after any playmacro "Petx" after reuse time
     1 PlayMacro(selfbuff1) Sleep (1800000) --30 minutes
     2 PlayMacro(selfbuff2) Sleep (600000) -- 10 minutes
     -- add more
     

     Skill Empower -- use after any playmacro "Petx" if none of then are 
  runing, can be at same time with  "Skill Sellbuff" list

       1 PlayMacro(Boost1) Reuse time = 480 seconds,Boosting time = 60 seconds
       2 PlayMacro(Boost2) Reuse time = 600 seconds, Boosting time = 180 seconds
       -- add more


  -- G1 = 2pet
  -- G2 = 3pet

 local function interruptable_sleep(delay)
   local tm = GetRunningTime() + delay
   repeat
      if IsKeyLockOn("scrolllock") then return true end
      local t = tm - GetRunningTime()
      if t > 0 then Sleep(math.min(t, 100)) end
   until t <= 0
 end

 function OnEvent(event, arg)
   if event=="G_PRESSED" and arg==1 then
      repeat
         local exit
         for _, phase in ipairs{
            {macro = "Basicos1", sleep_macro = 16000, },
            {macro = "Pick",     sleep_macro = 2000,  },
            {macro = "Pet1",     sleep_macro = 2000,  },
         -- if  on reuse PlayMacro(selfbuff1),PlayMacro(Selfbuff2), may add more
         -- if  on reuse PlayMacro(boots1),PlayMacro(boost2) may add some
            {macro = "Basicos1", sleep_macro = 16000, },
            {macro = "Pick",     sleep_macro = 2000,  },
            {macro = "Pet2",     sleep_macro = 2000,  },
         -- if  on reuse PlayMacro(selfbuff1),PlayMacro(Selfbuff2), may add more
         -- if  on reuse PlayMacro(boots1),PlayMacro(boost2) may add some
            {macro = "Basicos1", sleep_macro = 16000, },
            {macro = "Pick",     sleep_macro = 2000,  },
         } do
            PlayMacro(phase.macro)
            exit = interruptable_sleep(phase.sleep_macro)
            AbortMacro()
            if exit then break end
         end
      until exit
      PressAndReleaseKey("scrolllock")
   end
 end

非常感谢你的帮助,但我不太明白, 我认为之前的解释还不够 我知道我对编程了解不多,但我逐渐明白了一些事情

这是我给你的完整剧本

local function interruptable_sleep(delay)
local tm = GetRunningTime() + delay
 repeat
  if IsKeyLockOn("scrolllock") then return true end
  local t = tm - GetRunningTime()
  if t > 0 then Sleep(math.min(t, 100)) end
until t <= 0
end

function OnEvent(event, arg)
 if event=="G_PRESSED" and arg==1 then
  repeat
     local exit
     for _, phase in ipairs{
        {macro = "Basicos1", sleep_macro = 16000, },
        {macro = "Pick",     sleep_macro = 2000,  },
        {macro = "Pet1",     sleep_macro = 2000,  },
        {macro = "Basicos1", sleep_macro = 16000, },
        {macro = "Pick",     sleep_macro = 2000,  },
        {macro = "Pet2",     sleep_macro = 2000,  },
        {macro = "Basicos1", sleep_macro = 16000, },
        {macro = "Pick",     sleep_macro = 2000,  },
     } do
        PlayMacro(phase.macro)
        exit = interruptable_sleep(phase.sleep_macro)
        AbortMacro()
        if exit then break end
     end
  until exit
    Sleep(250)
  PressAndReleaseKey("scrolllock")
  elseif event=="G_PRESSED" and arg==2 then
  repeat
     local exit
     for _, phase in ipairs{
        {macro = "Basicos1", sleep_macro = 16000, },
        {macro = "Pick",     sleep_macro = 2000,  },
        {macro = "Pet1",     sleep_macro = 2000,  },
        {macro = "Basicos1", sleep_macro = 16000, },
        {macro = "Pick",     sleep_macro = 2000,  },
        {macro = "Pet2",     sleep_macro = 2000,  },
        {macro = "Basicos1", sleep_macro = 16000, },
        {macro = "Pick",     sleep_macro = 2000,  },
        {macro = "Pet3",     sleep_macro = 2000,  },
        {macro = "Basicos1", sleep_macro = 16000, },
        {macro = "Pick",     sleep_macro = 2000,  },
     } do
        PlayMacro(phase.macro)
        exit = interruptable_sleep(phase.sleep_macro)
        AbortMacro()
        if exit then break end
     end
  until exit
    Sleep(250)
  PressAndReleaseKey("scrolllock")
  elseif event=="G_PRESSED" and arg==3 then
  repeat
     local exit
     for _, phase in ipairs{
        {macro = "Basicos1",    sleep_macro = 13000, },
        {macro = "Pick",        sleep_macro = 1000,  },
        {macro = "PetLargo1",   sleep_macro = 2800,  },
        {macro = "Basicos1",    sleep_macro = 13000, },
        {macro = "Pick",        sleep_macro = 1000,  },
        {macro = "PetLargo2",   sleep_macro = 2800,  },
     } do
        PlayMacro(phase.macro)
        exit = interruptable_sleep(phase.sleep_macro)
        AbortMacro()
        if exit then break end
     end
  until exit
    Sleep(250)
  PressAndReleaseKey("scrolllock")
  elseif event=="G_PRESSED" and arg==4 then
  repeat
     local exit
     for _, phase in ipairs{
        {macro = "Basicos1",    sleep_macro = 16000, },
        {macro = "Pick",        sleep_macro = 2000,  },
        {macro = "PetLargo1",   sleep_macro = 2800,  },
        {macro = "Basicos1",    sleep_macro = 16000, },
        {macro = "Pick",        sleep_macro = 2000,  },
        {macro = "PetLargo2",   sleep_macro = 2800,  },
        {macro = "Basicos1",    sleep_macro = 16000, },
        {macro = "Pick",        sleep_macro = 2000,  },
        {macro = "PetLargo3",   sleep_macro = 2800,  },
        {macro = "Basicos1",    sleep_macro = 16000, },
        {macro = "Pick",        sleep_macro = 2000,  },
     } do
        PlayMacro(phase.macro)
        exit = interruptable_sleep(phase.sleep_macro)
        AbortMacro()
        if exit then break end
     end
    until exit
    Sleep(250)
    PressAndReleaseKey("scrolllock")
    elseif event=="G_PRESSED" and arg==5 then
    repeat
     local exit
     for _, phase in ipairs{
        {macro = "Basicos1",    sleep_macro = 16000,},
        {macro = "Pick",        sleep_macro = 500,},
     } do
        PlayMacro(phase.macro)
        exit = interruptable_sleep(phase.sleep_macro)
        AbortMacro()
        if exit then break end
     end
    until exit
    Sleep(250)
   PressAndReleaseKey("scrolllock")
  end
 end

专为游戏中不同地点的自动农场而设计

I will like to G1 on and G2 off.

IMO,无法使用 G2 或 G1 停止您的脚本。
但是你可以使用 ScrollLock 键来停止脚本:

最初 ScrollLock LED 熄灭。
你按下 G1,脚本开始。
当脚本为 运行 时,您按下 ScrollLock,其 LED 亮起。
脚本完成其工作并关闭 ScrollLock LED。

function OnEvent(event, arg)
    if event=="G_PRESSED" and arg==1 then
        repeat
            for _, Fkey in ipairs{"F1", "F2"} do
                PlayMacro("Basicos")
                for t = 1, 20 do
                    Sleep(1000)
                    if IsKeyLockOn("scrolllock") then break end
                end
                AbortMacro()
                PressAndReleaseKey(Fkey)
                if IsKeyLockOn("scrolllock") then break end
                Sleep(1500)
            end
        until IsKeyLockOn("scrolllock")   -- is ScrollLock LED on?
        PressAndReleaseKey("scrolllock")  -- turn it off
    end
end

更新

local function interruptable_sleep(delay)
   local tm = GetRunningTime() + delay
   repeat
      if IsKeyLockOn("scrolllock") then return true end
      local t = tm - GetRunningTime()
      if t > 0 then Sleep(math.min(t, 100)) end
   until t <= 0
end

function OnEvent(event, arg)
   if event=="G_PRESSED" and arg==1 then
      repeat
         local exit
         for _, phase in ipairs{
            {macro = "Basicos", sleep_macro = 13000, fkey = "F1", sleep_fkey = 2000},
            {macro = "Basicos", sleep_macro = 15000, fkey = "F2", sleep_fkey = 1800},
            {macro = "BUFF",    sleep_macro = 5000,  fkey = "F3", sleep_fkey = 2500},
         } do
            PlayMacro(phase.macro)
            exit = interruptable_sleep(phase.sleep_macro)
            AbortMacro()
            if exit then break end
            PressAndReleaseKey(phase.fkey)
            exit = interruptable_sleep(phase.sleep_fkey)
            if exit then break end
         end
      until exit
      PressAndReleaseKey("scrolllock")  
   end
end

更新 #2

-- G1 = 2pet
-- G2 = 3pet

local function interruptable_sleep(delay)
   local tm = GetRunningTime() + delay
   repeat
      if IsKeyLockOn("scrolllock") then return true end
      local t = tm - GetRunningTime()
      if t > 0 then Sleep(math.min(t, 100)) end
   until t <= 0
end

function OnEvent(event, arg)
   if event=="G_PRESSED" and arg==1 then
      repeat
         local exit
         for _, phase in ipairs{
            {macro = "Basicos1", sleep_macro = 16000, },
            {macro = "Pick",     sleep_macro = 2000,  },
            {macro = "Pet1",     sleep_macro = 2000,  },
            {macro = "Basicos1", sleep_macro = 16000, },
            {macro = "Pick",     sleep_macro = 2000,  },
            {macro = "Pet2",     sleep_macro = 2000,  },
            {macro = "Basicos1", sleep_macro = 16000, },
            {macro = "Pick",     sleep_macro = 2000,  },
         } do
            PlayMacro(phase.macro)
            exit = interruptable_sleep(phase.sleep_macro)
            AbortMacro()
            if exit then break end
         end
      until exit
      PressAndReleaseKey("scrolllock")
   elseif event=="G_PRESSED" and arg==2 then
      local loop_ctr = 0
      repeat
         local exit
         loop_ctr = loop_ctr + 1
         for _, phase in ipairs{
            {macro = "Basicos1", sleep_macro = 16000, skip_on_first_loop = false, },
            {macro = "Pick",     sleep_macro = 2000,  skip_on_first_loop = false, },
            {macro = "Pet1",     sleep_macro = 2000,  skip_on_first_loop = false, },
            {macro = "Basicos1", sleep_macro = 16000, skip_on_first_loop = false, },
            {macro = "Pick",     sleep_macro = 2000,  skip_on_first_loop = false, },
            {macro = "Pet2",     sleep_macro = 2000,  skip_on_first_loop = false, },
            {macro = "Basicos1", sleep_macro = 16000, skip_on_first_loop = false, },
            {macro = "Pick",     sleep_macro = 2000,  skip_on_first_loop = false, },
            {macro = "Pet3",     sleep_macro = 2000,  skip_on_first_loop = false, },
            {macro = "Basicos1", sleep_macro = 16000, skip_on_first_loop = false, },
            {macro = "Pick",     sleep_macro = 2000,  skip_on_first_loop = false, },
         } do
            if loop_ctr > 1 or not phase.skip_on_first_loop then
               PlayMacro(phase.macro)
               exit = interruptable_sleep(phase.sleep_macro)
               AbortMacro()
               if exit then break end
            end
         end
      until exit
      PressAndReleaseKey("scrolllock")
   end
end