EigeenLoader/utils/Keypad.lua

38 lines
991 B
Lua
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- 猫猫虫的 LuaEngine 工具模块Keypad
-- @version: 1.0.1
local Keypad = {}
--- 带计时器的按键触发操作
---@param keypadID number|string|table
---@param chrono number
---@param handler fun()
---@param xbox boolean|nil
function Keypad.UseChronoscope(keypadID, chrono, handler, xbox)
if not keypadID or not chrono or not handler then
return
end
if chrono < 0 then
return
end
if type(xbox) ~= "boolean" then
xbox = nil
end
local keypadIDStr = keypadID
if type(keypadID) == "number" then
keypadIDStr = tostring(keypadID)
elseif type(keypadID) == "table" then
keypadIDStr = table.concat(keypadID, ",")
end
local keypadShortcut = "keypad_keyCD_" .. keypadIDStr
if engine.keypad(keypadID, xbox) and
(CheckChronoscope(keypadShortcut) or not CheckPresenceChronoscope(keypadShortcut)) then
AddChronoscope(chrono, keypadShortcut)
handler()
end
end
return Keypad