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)