mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-17 15:06:02 +01:00
feat(client/keybinds): added isPressed state for keybinds (#643)
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user