Methods
Getting Started
This page shows all the functions of UserInput as well as functions specifically for the mouse.
Methods
UserInput.new (Constructor)
new(config: UserInputConfiguration): UserInputComponent
Creates a new UserInput component instance.
Parameters config: Configuration object with the following properties:
Keys: {Enum.KeyCode | Enum.UserInputType | string} - Array of keys to register
InputType: "Gamepad" | "Keyboard" | "Mouse" - Initial input type
UserInput:Pressed
Pressed(callback : (Enum.KeyCode | Enum.UserInputType)) -> SignalConnection
Public method to connect a callback to the key pressed event
- @param callback: Function that will be called when a registered key is pressed
- @return: SignalConnection that can be used to disconnect the callback
UserInput:Released
Released(callback : (Enum.KeyCode | Enum.UserInputType)) -> SignalConnection
Public method to connect a callback to the key released event
- @param callback: Function that will be called when a registered key is released
- @return: SignalConnection that can be used to disconnect the callback
UserInput:Observe
Observe(callback : ("Gamepad" | "MouseKeyboard" | "Touch")) -> () -> ()
Observe changes in the user's preferred input method
- @param callback: Function called when input type changes (Gamepad, MouseKeyboard, or Touch)
- @return: Cleanup function to stop observing
UserInput:GetInputType
GetInputType() -> "Gamepad" | "MouseKeyboard" | "Touch"
Returns the current input type
- @return: "Gamepad" | "MouseKeyboard" | "Touch" - Current input type
UserInput:ChangeInputType
ChangeInputType("Gamepad" | "Keyboard" | "Mouse",Keys : {Enum.KeyCode | Enum.UserInputType | string}
Dynamically change the input type between Gamepad and Keyboard or Mouse This will clear all registered keys and recreate the input handlers
Note
-
Pressed and Release connection don't need to be reconnected.
-
You dont need to pass an array of keys.
UserInput:ChangeKey
ChangeKey({Enum.KeyCode | Enum.UserInputType | string})
Replace all currently registered keys with a new set
- @param Keys: Keys to register
UserInput:AddKey
AddKey({Enum.KeyCode | Enum.UserInputType | string})
Add new keys to the existing registered set Duplicate keys are automatically ignored
- @param Keys: Keys to add
UserInput:RemoveKey
RemoveKey({Enum.KeyCode | Enum.UserInputType | string})
Remove specific keys from the registered set
- @param Keys: Keys to remove
UserInput:BindToGuiVisibility
Allow you to disable InputsComponent from firing events when the gui visibility changes
examples:
- false = input disabled
- true = input enabled
this allow to bind only 1 gui if you try to change it the old one will be disconnected and removed and- the InputComponent will no longer depend on the old one.
@param Gui : GuiObject - Gui object to bind to
UserInput:HasGui
Allow you to see if the InputComponent is binded to a gui
@return boolean
UserInput:Enable
Enables the UserInputComponent and all of its signals
UserInput:Disable
Disables the UserInputComponent and all of its signals (they are not disconnected !)
UserInput:Disconnect
Note
Multiple Disconnect function exist you will find everything about disconnection here
DisconnectPressed
DisconnectPressed
Disconnect all callbacks connected to the KeyPressed signal
DisconnectReleased
DisconnectReleased
Disconnect all callbacks connected to the KeyReleased signal
DisconnectMiddleUp
@MouseOnly - DisconnectMiddleUpSignal
Disconnect the middle mouse button up signal
DisconnectMiddleDown
@MouseOnly - DisconnectMiddleDownSignal
Disconnect the middle mouse button down signal
DisconnectScrolled
@MouseOnly - DisconnectScrolledSignal
Disconnect the scroll signal from the mouse
DisconnectMoved
@MouseOnly - DisconnectMovedSignal
Disconnect the signal when the mouse move
DisconnectAll
DisconnectAll
Disconnect all signals
UserInput:Destroy()
Destroy
Complete cleanup of the UserInput component This should be called when the component is no longer needed