The user's input can be accessed in three ways:
- through a InputObject which is passed by the events InputBegan, InputChanged and InputEnded of either the UserInputService service or a UI element (GuiObject)
- binding a UserInputType through the ContextActionService service
- through the Mouse object which can be accessed either by the GetMouse function of a Player, the GetMouse function of a Plugin, or the Equipped event of a Tool (this is considered the legacy way of accessing the mouse and keyboard input, and is considered superseded by the others as it does not account for other inputs such as the touch input)
History[]
The UserInputService and ContextActionService services were introduced sometime in 2014. Previously, the Mouse class was the primary way of accessing mouse and keyboard input.
At some point, the KeyUp and KeyDown events of the Mouse class were deprecated in favor of the new services.
UserInputType[]
The UserInputType enum represents a type of user input. There are 21 UserInputTypes:
- Mouse inputs:
- MouseButton1 (defaulted to left-click)
- MouseButton2 (defaulted to right-click)
- MouseButton3 (defaulted to middle-click)
- MouseWheel (refers to scrolling)
- MouseMovement
- Touch (refers to touchscreen input)
- Keyboard
- Focus (refers to the client regaining focus of the Roblox window)
- Mobile inputs:
- Accelerometer (represents the device's acceleration in the real world)
- Gyro (represents the device's orientation and angular velocity in the real world)
- Gamepad1 to Gamepad8 (represents each USB gamepad that is connected)
- TextInput (refers to input of Text into a TextBox)
- InputMethod (refers to Text input from an input method editor)
- None
InputObject[]
User inputs are represented as InputObjects. InputObjects are passed by the events InputBegan, InputChanged and InputEnded of either the UserInputService service or a UI element (GuiObject). InputObjects have the UserInputType property.
Binding[]
UserInputTypes can be binded through the ContextActionService service.
Mouse class[]
The Mouse is a class that represents the user's mouse (although it has keyboard input events KeyUp and KeyDown) and has two sub-classes: PlayerMouse and PluginMouse.
The Mouse object is passed by the Equipped event of a Tool. The PlayerMouse is accessed through the GetMouse function of a Player. This function can only be called from the client. The PluginMouse is accessed through the GetMouse function of the Plugin object.
External links[]
Programming |
| ||||||
---|---|---|---|---|---|---|---|
Design | |||||||
Assets | |||||||
Tools | |||||||
Monetization | |||||||
Analytics | Developer Stats · Monthly active users (MAU) | ||||||
Advertising | |||||||
Resources |