脚本不停止只键盘

问题描述

大家好,我有一个键盘 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",-- if  on reuse PlayMacro(selfbuff1),PlayMacro(Selfbuff2),may add more
         -- if  on reuse PlayMacro(boots1),PlayMacro(boost2) may add some
            {macro = "Basicos1",{macro = "Pet2",} 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",{macro = "Basicos1",} 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 _,{macro = "Pet3",} 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 _,sleep_macro = 13000,sleep_macro = 1000,{macro = "PetLargo1",sleep_macro = 2800,{macro = "PetLargo2",} 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 _,{macro = "PetLargo3",} 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 _,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

专为汽车农业游戏中的不同地点而设计

解决方法

我想开 G1 关 G2。

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,phase in ipairs{
            {macro = "Basicos1",sleep_macro = 16000,},{macro = "Pick",sleep_macro = 2000,{macro = "Pet1",{macro = "Basicos1",{macro = "Pet2",} 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 _,skip_on_first_loop = false,{macro = "Pet3",} 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