UserInputService Methods similar to GetPropertyChangedSignal

UserInputService’s events are universal, meaning they fire for every input, even if the callback doesn’t do anything with it.

That means to make the console print something every time the player presses E, you would have to filter out the Input.KeyCode and WasProcessed arguments every callback.

local function OnInputBegan(Input: InputObject, WasProcessed: boolean)
	if Input.KeyCode == Enum.KeyCode.E and not WasProcessed then
		print("Pressed E")
	end
end

UserInputService.InputBegan:Connect(OnInputBegan)

The Proposal

Just like Instance/GetPropertyChangedSignal, add methods to UserInputService that return dedicated signals for the specified UserInputTypes and KeyCodes.

For example, a GetKeyCodeBeganSignal would have the signature (keyCode: Enum.KeyCode, processed: boolean?) -> RBXScriptConnection.

local function OnPressed()
	print("Pressed E")
end

UserInputService:GetKeyCodeBeganSignal(Enum.KeyCode.E, false):Connect(OnPressed)

If processed is true/false, it will only fire for that gameProcessedEvent. Otherwise, it allows all inputs.

This would also be extended for the Ended and Changed variants, as well.

2 Likes

Don’t we already have ContextActionService?

2 Likes

ContextActionService binds contextually, while UserInputService provides input-based signals.

I cannot get a RbxScriptSignal from a ContextActionService subscription, so I have to rely on remembering what name I gave each bind + making sure they don’t clash with others.

1 Like

I don’t think your inability to properly use ContextActionService is a good enough use case to justify a new addition to UserInputService’s API.

3 Likes