0

我想要做的是,如果我按下鼠标上的按钮,它会使用像“E”这样的键,如果我再次按下按钮,它会使用“W”键,2 秒后它会重置,我的意思是如果我不这样做2 秒后按下相同的按钮,它再次使用字母“e”。那可能吗?

我已经尝试了一些代码,但还没有结果:

  function OnEvent(event, arg, family)
    if event == "MOUSE_BUTTON_PRESSED" and arg == 5 then 
    toggle = not toggle
    if toggle then
      PressKey("e")
      ReleaseKey("e") 
    else  
      PressKey("w")
      ReleaseKey("w")
    end
  end
end
4

1 回答 1

0
local prev_tm_btn5 = -math.huge

function OnEvent(event, arg, family)
   if event == "MOUSE_BUTTON_PRESSED" and arg == 5 then
      local tm = GetRunningTime()
      local key = tm - prev_tm_btn5 > 2000 and "e" or "w"
      prev_tm_btn5 = tm
      PressKey(key)
      Sleep(15)
      ReleaseKey(key)
   end
end
于 2020-05-28T14:41:55.057 回答