Skip to content

[Bug] Keybind isPressed stuck to true when disabled during key hold #96

@Primordial-Devv

Description

@Primordial-Devv

When a keybind is disabled while the key is being held down, the isPressed state remains true permanently because the (release) command handler returns early when data.disabled is true, skipping the data.isPressed = false reset.

To Reproduce
1. Create a keybind with lib.addKeybind
2. Press and hold the bound key → isPressed becomes true
3. While still holding the key, disable the keybind (keybind:disable(true))
4. Release the key → the - handler returns early due to data.disabled, isPressed stays true
5. Re-enable the keybind → isPressed is still true even though the key is not held

Expected behavior
isPressed should be set to false on key release regardless of the disabled state. The disabled check should only prevent the onReleased callback from firing, not the state reset.

Suggested fix
In the command handler, reset isPressed before the disabled check:

    RegisterCommand('-' .. data.name, function()
        data.isPressed = false
        if data.disabled or IsPauseMenuActive() then return end
        if data.onReleased then data:onReleased() end
    end)

Additional context

This can cause unexpected behavior in any code that relies on keybind.isPressed or keybind:isControlPressed() to determine if a key is currently held, as it will report true indefinitely after this sequence occurs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions