UserInputServiceクラス
ひとことで言うと
キーボード・マウス・タッチ・ゲームパッドの入力を調べるサービスです(LocalScriptで使います)。
公式の説明(英語):UserInputService is primarily used to detect the input types available on a user's device, as well as detect input events.
使用例
local UserInputService = game:GetService("UserInputService")
UserInputService.InputBegan:Connect(function(input, gameProcessed)
if gameProcessed then
return
end
if input.KeyCode == Enum.KeyCode.E then
print("Eキーが押された")
end
end)スクリプトは、Luauの型チェック(luau-lsp)で確認しています。
クラスの関係
プロパティ(15)
| 名前と書き方 | 説明 |
|---|---|
AccelerometerEnabledUserInputService.AccelerometerEnabled: boolean | Describes whether the user's device has an accelerometer. |
GamepadEnabledUserInputService.GamepadEnabled: boolean | Describes whether the user's device has an available gamepad. |
GyroscopeEnabledUserInputService.GyroscopeEnabled: boolean | Describes whether the user's device has a gyroscope. |
KeyboardEnabledUserInputService.KeyboardEnabled: boolean | Describes whether the user's device has a keyboard available. |
MouseBehaviorUserInputService.MouseBehavior: MouseBehavior | Determines whether the user's mouse can be moved freely or is locked. |
MouseDeltaSensitivityUserInputService.MouseDeltaSensitivity: float | Scales the delta (change) output of the user's Mouse. |
MouseEnabledUserInputService.MouseEnabled: boolean | Describes whether the user's device has a mouse available. |
MouseIconUserInputService.MouseIcon: ContentId | The content ID of the image for the user's mouse icon. |
MouseIconContentUserInputService.MouseIconContent: Content | The content ID of the image for the user's mouse icon. Only supports asset URIs. |
MouseIconEnabledUserInputService.MouseIconEnabled: boolean | Determines whether the mouse icon is visible. |
OnScreenKeyboardPositionUserInputService.OnScreenKeyboardPosition: Vector2 | Determines the position of the on-screen keyboard. |
OnScreenKeyboardSizeUserInputService.OnScreenKeyboardSize: Vector2 | Determines the size of the on-screen keyboard. |
OnScreenKeyboardVisibleUserInputService.OnScreenKeyboardVisible: boolean | Describes whether an on-screen keyboard is currently visible on the user's screen. |
PreferredInputUserInputService.PreferredInput: PreferredInput | Queries the primary input type a player is using, based on anticipated user behavior. |
TouchEnabledUserInputService.TouchEnabled: boolean | タッチ操作ができる端末かどうか。Describes whether the user's device has a touch screen available. |
メソッド(24)
| 名前と書き方 | 説明 |
|---|---|
CreateVirtualInputUserInputService:CreateVirtualInput(target: Instance): Object | Creates a VirtualInput object for simulating mouse, keyboard, and pointer input. |
GamepadSupportsUserInputService:GamepadSupports(gamepadNum: UserInputType, gamepadKeyCode: KeyCode): boolean | Returns whether the given UserInputType gamepad supports a button corresponding with the given KeyCode. |
GetConnectedGamepadsUserInputService:GetConnectedGamepads(): Array | Returns an array of UserInputType gamepads currently connected. |
GetDeviceAccelerationUserInputService:GetDeviceAcceleration(): InputObject | Returns an InputObject that describes the device's current acceleration. |
GetDeviceGravityUserInputService:GetDeviceGravity(): InputObject | Returns an InputObject describing the device's current gravity vector. |
GetDeviceRotationUserInputService:GetDeviceRotation(): Tuple | Returns an InputObject and a CFrame describing the device's current rotation vector. |
GetFocusedTextBoxUserInputService:GetFocusedTextBox(): TextBox | Returns the TextBox the client is currently focused on. |
GetGamepadConnectedUserInputService:GetGamepadConnected(gamepadNum: UserInputType): boolean | Returns whether a gamepad with the given UserInputType is connected. |
GetGamepadStateUserInputService:GetGamepadState(gamepadNum: UserInputType): List<InputObject> | Returns an array of Class.InputObject|InputObjects for all available inputs on the given gamepad, representing each input's last input state. |
GetImageForKeyCodeUserInputService:GetImageForKeyCode(keyCode: KeyCode): ContentId | Returns an image for the requested KeyCode. |
GetKeysPressedUserInputService:GetKeysPressed(): List<InputObject> | Returns an array of Class.InputObject|InputObjects associated with the Enum.KeyCode|keys currently being pressed down. |
GetLastInputTypeUserInputService:GetLastInputType(): UserInputType | Returns the UserInputType associated with the user's most recent input. |
GetMouseButtonsPressedUserInputService:GetMouseButtonsPressed(): List<InputObject> | Returns an array of Class.InputObject|InputObjects associated with the mouse buttons currently being held down. |
GetMouseDeltaUserInputService:GetMouseDelta(): Vector2 | Returns the change, in pixels, of the position of the player's Mouse in the last rendered frame. Only works if the mouse is locked. |
GetMouseLocationUserInputService:GetMouseLocation(): Vector2 | Returns the current screen location of the player's Mouse relative to the top-left corner of the screen. |
GetNavigationGamepadsUserInputService:GetNavigationGamepads(): Array | Returns an array of gamepads connected and enabled for GuiObject navigation in descending order of priority. |
GetStringForKeyCodeUserInputService:GetStringForKeyCode(keyCode: KeyCode, format: KeyCodeStringFormat): string | Returns a string representing a key the user should press in order to input a given KeyCode, optionally in an abbreviated format. |
GetSupportedGamepadKeyCodesUserInputService:GetSupportedGamepadKeyCodes(gamepadNum: UserInputType): Array | Returns an array of Enum.KeyCode|KeyCodes that the gamepad associated with the given UserInputType supports. |
IsGamepadButtonDownUserInputService:IsGamepadButtonDown(gamepadNum: UserInputType, gamepadKeyCode: KeyCode): boolean | Determines whether a particular button is pressed on a gamepad. |
IsKeyDownUserInputService:IsKeyDown(keyCode: KeyCode): boolean | 指定したキーが押されているかを調べます。Returns whether the given Enum.KeyCode|key is currently held down. |
IsMouseButtonPressedUserInputService:IsMouseButtonPressed(mouseButton: UserInputType): boolean | Returns whether the given mouse button is currently held down. |
IsNavigationGamepadUserInputService:IsNavigationGamepad(gamepadEnum: UserInputType): boolean | Returns true if the specified gamepad is allowed to control navigation and selection Class.GuiObject|GuiObjects. |
RecenterUserHeadCFrameUserInputService:RecenterUserHeadCFrame(): () | Recenters the CFrame of the VR headset to the current orientation of the headset worn by the user. |
SetNavigationGamepadUserInputService:SetNavigationGamepad(gamepadEnum: UserInputType, enabled: boolean): () | Sets whether or not the specified gamepad can move the GuiObject navigator. |
イベント(26)
| 名前と書き方 | 説明 |
|---|---|
DeviceAccelerationChangedUserInputService.DeviceAccelerationChanged(acceleration: InputObject) | Fires when a user moves a device that has an accelerometer. |
DeviceGravityChangedUserInputService.DeviceGravityChanged(gravity: InputObject) | Fires when the force of gravity changes on a device that has an enabled accelerometer. |
DeviceRotationChangedUserInputService.DeviceRotationChanged(rotation: InputObject, cframe: CFrame) | Fires when a user rotates a device that has a gyroscope. |
GamepadConnectedUserInputService.GamepadConnected(gamepadNum: UserInputType) | Fires when a gamepad is connected to the client. |
GamepadDisconnectedUserInputService.GamepadDisconnected(gamepadNum: UserInputType) | Fires when a gamepad is disconnected from the client. |
InputBeganUserInputService.InputBegan(input: InputObject, gameProcessedEvent: boolean) | キーを押す・クリックするなど、入力が始まったときに発生するイベントです。Fires when a user begins interacting with an input device such as a mouse or gamepad. |
InputChangedUserInputService.InputChanged(input: InputObject, gameProcessedEvent: boolean) | Fires when a user changes how they're interacting with an input device such as a mouse or gamepad. |
InputEndedUserInputService.InputEnded(input: InputObject, gameProcessedEvent: boolean) | 入力が終わった(キーを離した)ときに発生するイベントです。Fires when a user stops interacting with an input device such as a mouse or gamepad. |
JumpRequestUserInputService.JumpRequest() | Fires whenever the client makes a request for their character to jump. |
LastInputTypeChangedUserInputService.LastInputTypeChanged(lastInputType: UserInputType) | Fires whenever the client's UserInputType is changed. |
PointerActionUserInputService.PointerAction(wheel: float, pan: Vector2, pinch: float, gameProcessedEvent: boolean) | Fires when the user performs a specific pointer action. |
TextBoxFocusedUserInputService.TextBoxFocused(textboxFocused: TextBox) | Fires when the client focuses on a TextBox. |
TextBoxFocusReleasedUserInputService.TextBoxFocusReleased(textboxReleased: TextBox) | Fires when the client loses focus on a TextBox. |
TouchDragUserInputService.TouchDrag(dragDirection: SwipeDirection, numberOfTouches: int, gameProcessedEvent: boolean) | Fires when the user drags on the screen of a Class.UserInputService.TouchEnabled|TouchEnabled device. |
TouchEndedUserInputService.TouchEnded(touch: InputObject, gameProcessedEvent: boolean) | Fires when a user releases their finger from the screen of a Class.UserInputService.TouchEnabled|TouchEnabled device. |
TouchLongPressUserInputService.TouchLongPress(touchPositions: Array, state: UserInputState, gameProcessedEvent: boolean) | Fires when a user holds at least one finger for a short amount of time on the screen of a Class.UserInputService.TouchEnabled|TouchEnabled device. |
TouchMovedUserInputService.TouchMoved(touch: InputObject, gameProcessedEvent: boolean) | Fires when a user moves their finger on the screen of a Class.UserInputService.TouchEnabled|TouchEnabled device. |
TouchPanUserInputService.TouchPan(touchPositions: Array, totalTranslation: Vector2, velocity: Vector2, state: UserInputState, gameProcessedEvent: boolean) | Fires when the user drags at least one finger on the screen of a Class.UserInputService.TouchEnabled|TouchEnabled device. |
TouchPinchUserInputService.TouchPinch(touchPositions: Array, scale: float, velocity: float, state: UserInputState, gameProcessedEvent: boolean) | Fires when a user performs a pinch gesture on the screen of a Class.UserInputService.TouchEnabled|TouchEnabled device. |
TouchRotateUserInputService.TouchRotate(touchPositions: Array, rotation: float, velocity: float, state: UserInputState, gameProcessedEvent: boolean) | Fires when a user rotates two fingers on the screen of a Class.UserInputService.TouchEnabled|TouchEnabled device. |
TouchStartedUserInputService.TouchStarted(touch: InputObject, gameProcessedEvent: boolean) | Fires when a user places their finger on the screen of a Class.UserInputService.TouchEnabled|TouchEnabled device. |
TouchSwipeUserInputService.TouchSwipe(swipeDirection: SwipeDirection, numberOfTouches: int, gameProcessedEvent: boolean) | Fires on a Class.UserInputService.TouchEnabled|TouchEnabled device when a user places their finger(s) down on the screen, pans across the screen, and lifts their finger(s) off with a certain speed of movement. |
TouchTapUserInputService.TouchTap(touchPositions: Array, gameProcessedEvent: boolean) | Fires when a user taps their finger on the screen of a Class.UserInputService.TouchEnabled|TouchEnabled device. |
TouchTapInWorldUserInputService.TouchTapInWorld(position: Vector2, processedByUI: boolean) | Fires when a user taps their finger on the screen of a Class.UserInputService.TouchEnabled|TouchEnabled device and the tap location is in the 3D world. |
WindowFocusedUserInputService.WindowFocused() | Fires when the window of the Roblox client gains focus on the user's screen. |
WindowFocusReleasedUserInputService.WindowFocusReleased() | Fires when the window of the Roblox client loses focus on the user's screen. |
受け継いでいるメンバー
Instance から受け継いでいるもの(46)
Archivable・Capabilities・IsInSandbox・Name・Parent・PredictionMode・Sandboxed・AddTag・ClearAllChildren・Clone・Destroy・FindFirstAncestor・FindFirstAncestorOfClass・FindFirstAncestorWhichIsA・FindFirstChild・FindFirstChildOfClass・FindFirstChildWhichIsA・FindFirstDescendant・GetActor・GetAttribute・GetAttributeChangedSignal・GetAttributes・GetChildren・GetDebugId・GetDescendants・GetFullName・GetStyled・GetStyledPropertyChangedSignal・GetTags・HasTag・IsAncestorOf・IsDescendantOf・IsPropertyModified・QueryDescendants・RemoveTag・ResetPropertyToDefault・SetAttribute・WaitForChild・AncestryChanged・AttributeChanged・ChildAdded・ChildRemoved・DescendantAdded・DescendantRemoving・Destroying・StyledPropertiesChanged
Object から受け継いでいるもの(4)
UserInputServiceを使う記事
英語の説明とメンバーの一覧は、Roblox Creator Documentation(UserInputService)をもとにしています(CC BY 4.0)。日本語の解説は、このサイトで独自に書いたものです。