How to re-enable arrow keys

How do I re-enable the arrow keys after disabling them like this:

ContextActionService:BindActionAtPriority("DisableArrowKeys", function()
	return Enum.ContextActionResult.Sink
end, false, Enum.ContextActionPriority.High.Value, Enum.KeyCode.Up, Enum.KeyCode.Down, Enum.KeyCode.Left, Enum.KeyCode.Right)

You can do ContextActionService:UnbindAction("DisableArrowKeys")

This does work how I want it, but is there any way to tell when the player is holding down the button?

You can use the UserInputService to listen for key press and key release events.

local ContextActionService = game:GetService("ContextActionService")
local UserInputService = game:GetService("UserInputService")

-- Unbind the action to re-enable the arrow keys
ContextActionService:UnbindAction("DisableArrowKeys")

-- Table to keep track of which keys are being held down
local keysHeldDown = {
    [Enum.KeyCode.Up] = false,
    [Enum.KeyCode.Down] = false,
    [Enum.KeyCode.Left] = false,
    [Enum.KeyCode.Right] = false
}

-- Function to handle key press
local function onKeyPress(input, gameProcessed)
    if gameProcessed then return end

    if keysHeldDown[input.KeyCode] ~= nil then
        keysHeldDown[input.KeyCode] = true
        print(input.KeyCode.Name .. " is being held down")
    end
end

-- Function to handle key release
local function onKeyRelease(input, gameProcessed)
    if gameProcessed then return end

    if keysHeldDown[input.KeyCode] ~= nil then
        keysHeldDown[input.KeyCode] = false
        print(input.KeyCode.Name .. " was released")
    end
end

-- Connect input events
UserInputService.InputBegan:Connect(onKeyPress)
UserInputService.InputEnded:Connect(onKeyRelease)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.