From 7bd22441fff2ce760a44df3334f377b480c35830 Mon Sep 17 00:00:00 2001 From: Geden420 <70329896+Geden420@users.noreply.github.com> Date: Mon, 16 Sep 2024 09:45:46 +0200 Subject: [PATCH] feat(client/keybinds): added isPressed state for keybinds (#643) --- imports/addKeybind/client.lua | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/imports/addKeybind/client.lua b/imports/addKeybind/client.lua index 904364693..4c6909df6 100644 --- a/imports/addKeybind/client.lua +++ b/imports/addKeybind/client.lua @@ -14,8 +14,10 @@ if cache.game == 'redm' then return end ---@class CKeybind : KeybindProps ---@field currentKey string ---@field disabled boolean +---@field isPressed boolean ---@field hash number ---@field getCurrentKey fun(): string +---@field isControlPressed fun(): boolean local keybinds = {} @@ -24,6 +26,7 @@ local GetControlInstructionalButton = GetControlInstructionalButton local keybind_mt = { disabled = false, + isPressed = false, defaultKey = '', defaultMapper = 'keyboard', } @@ -36,6 +39,10 @@ function keybind_mt:getCurrentKey() return GetControlInstructionalButton(0, self.hash, true):sub(3) end +function keybind_mt:isControlPressed() + return self.isPressed +end + function keybind_mt:disable(toggle) self.disabled = toggle end @@ -48,13 +55,15 @@ function lib.addKeybind(data) keybinds[data.name] = setmetatable(data, keybind_mt) RegisterCommand('+' .. data.name, function() - if not data.onPressed or data.disabled or IsPauseMenuActive() then return end - data:onPressed() + if data.disabled or IsPauseMenuActive() then return end + data.isPressed = true + if data.onPressed then data:onPressed() end end) RegisterCommand('-' .. data.name, function() - if not data.onReleased or data.disabled or IsPauseMenuActive() then return end - data:onReleased() + if data.disabled or IsPauseMenuActive() then return end + data.isPressed = false + if data.onReleased then data:onReleased() end end) RegisterKeyMapping('+' .. data.name, data.description, data.defaultMapper, data.defaultKey)