UserInputService methods not tracking gamepad input

The methods IsKeyDown and GetKeysPressed do not seem to track KeyCode enums from gamepads and input objects created by gamepads.The ideal desired behavior is that they should track and return their respective true values/objects.


user input service gamepad bug repro.rbxl (12.4 KB)

The bug from the tests I’ve done and had other completed is 100% reproducible by doing the following:

(if running the test from the attached repro file skip to step 4)

  1. Open a new place or use an existing open place
  2. Make and place a LocalScript in a service where it will run
  3. Set the LocalScripts source to the code snip it shown below
  4. Press play solo or Start a server with a client
  5. Press any buttons on a connected gamepad and observe no acknowledgment of the input in the Output window
local userInput = game:GetService("UserInputService")

local testEnums	= {
	Enum.KeyCode.ButtonA,
	Enum.KeyCode.ButtonB,
	Enum.KeyCode.ButtonX,
	Enum.KeyCode.ButtonY,
	
	Enum.KeyCode.ButtonL1,
	Enum.KeyCode.ButtonL2,
	Enum.KeyCode.ButtonL3,
	
	Enum.KeyCode.ButtonR1,
	Enum.KeyCode.ButtonR2,
	Enum.KeyCode.ButtonR3,
	
	Enum.KeyCode.DPadUp,
	Enum.KeyCode.DPadDown,
	Enum.KeyCode.DPadLeft,
	Enum.KeyCode.DPadRight,
	
	Enum.KeyCode.ButtonSelect,
	Enum.KeyCode.ButtonStart,
}

while wait() do
	print("IsKeyDown() results:")
	for _, enum in next, testEnums do
		local value = tostring(userInput:IsKeyDown(enum))
		local spacing = 15 - #enum.Name
		
		print(enum.Name..string.rep(" ", spacing)..value)
	end
	
	print(string.rep("-", 20))
	print("GetKeysPressed() results:")
	
	for _, object in next, userInput:GetKeysPressed() do
		print(object.KeyCode.Name)
	end	

	print(string.rep("-", 20))
end

I’m unaware of when this started happening, it was only as of this post that I began noticing it. If this is intended behavior then there is a lack of documentation on the wiki stating the aforementioned methods are strictly for keyboard input regardless of keyboard and gamepad inputs being grouped into the same Enum group.

2 Likes

Shouldn’t you use GetGamepadState to do this anyway?

3 Likes

huh, yea probably

.-.

Also, a fun little tip with it: Map the states to their corresponding KeyCodes, and then you can always reference them. They are mutable; you don’t have to keep calling GetGamepadState:

local _states = game:GetService("UserInputService"):GetGamepadState(Enum.UserInputType.Gamepad1)
local states = {}
for _,state in pairs(_states) do
	states[state.KeyCode] = state
end

-- Poll the Thumbstick position:
local thumbstick1 = states[Enum.KeyCode.Thumbstick1]
while true do
	wait(0.1)
	print(thumbstick1.Position)
end
3 Likes

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