I'm trying to get which key the character is pressing down without using both InputBegan and InputEnded. I'm trying to do it in a more clever way, but the problem is that it's not registering any of the keys I'm pressing, all it's printing is: Enum.Keycode.Unknown
-- Services
local UserInputService = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")
humanoid:ChangeState(Enum.HumanoidStateType.Physics)
local ButtonsHeld = {}
local MoveVector = Vector3.new()
local MoveVectors = {
[Enum.KeyCode.W] = Vector3.new(0, 0, -1),
[Enum.KeyCode.A] = Vector3.new(-1, 0, 0),
[Enum.KeyCode.S] = Vector3.new(0, 0, 1),
[Enum.KeyCode.D] = Vector3.new(-1, 0, 0),
}
function onInputChanged(input, gameProcessed)
print(input.KeyCode)
if (MoveVectors[input.KeyCode]) and (input.UserInputType == Enum.UserInputType.TextInput) then
if (input.UserInputState == Enum.UserInputState.Begin) then
if (not ButtonsHeld[input.KeyCode]) then
ButtonsHeld[input.KeyCode] = true
MoveVector = MoveVector + MoveVector[input.KeyCode]
end
elseif (input.UserInputState == Enum.UserInputState.End) then
if (ButtonsHeld[input.KeyCode]) then
ButtonsHeld[input.KeyCode] = false
MoveVector = MoveVector - MoveVector[input.KeyCode]
end
end
end
end
UserInputService.InputChanged:Connect(onInputChanged)

3 comments
try using tostring() for the print
when the mouse is clicked or a unknown button ex: function button on laptops is pressed it will be a unknown keycode
Better question is, why dont you want to use imput began and imput ended. This is literally why they exist.