PreferredInput
This item only works when running on the client. Client
A helper library for observing the preferred user input of the player. This is useful for determining what input schemes to use during gameplay. A player might switch from using a mouse to a gamepad mid-game, and it is important for the game to respond to this change.
The PreferredInput library is part of the Input package.
local PreferredInput = require(packages.Input).PreferredInput
Functions
observe
PreferredInput.observe(handler: (preferred: Enum.PreferredInput) → (() → ())?) → () → ()Observes the preferred input. In other words, the handler function will be fired immediately, as well as any time the preferred input changes.
The returned function can be called to disconnect the observer.
local disconnect = PreferredInput.observe(function(preferred)
-- Fires immediately & any time the preferred input changes
print(preferred)
return function()
-- Preferred input has changed
end
end)
-- If/when desired, observer can be stopped by calling the returned function:
disconnect()
get
PreferredInput.get() → Enum.PreferredInput
Gets the preferred input. This is equivalent to
UserInputService.PreferredInput.