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 Preferred class is part of the Input package.
local PreferredInput = require(packages.Input).PreferredInput
Types
InputType
The InputType is just a string that is either "MouseKeyboard"
,
"Touch"
, or "Gamepad"
.
Properties
Current
This item is read only and cannot be modified. Read OnlyPreferredInput.Current:
InputType
The current preferred InputType.
print(PreferredInput.Current)
Functions
Observe
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)
end)
-- If/when desired, observer can be stopped by calling the returned function:
disconnect()