# UserInputService(ロブロックス クラス) > キーボード・マウス・タッチ・ゲームパッドの入力を調べるサービスです(LocalScriptで使います)。 - URL:https://roblox.minecraft-okinawa.com/reference/classes/UserInputService/ - 公式:https://create.roblox.com/docs/reference/engine/classes/UserInputService - 受け継いでいるクラス:Instance ## 使用例:キーボードのEキーを押したことを調べる (LocalScript/置く場所:StarterPlayerScripts) ```lua 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) ``` ## プロパティ - `UserInputService.AccelerometerEnabled: boolean`:Describes whether the user's device has an accelerometer. - `UserInputService.GamepadEnabled: boolean`:Describes whether the user's device has an available gamepad. - `UserInputService.GyroscopeEnabled: boolean`:Describes whether the user's device has a gyroscope. - `UserInputService.KeyboardEnabled: boolean`:Describes whether the user's device has a keyboard available. - `UserInputService.MouseBehavior: MouseBehavior`:Determines whether the user's mouse can be moved freely or is locked. - `UserInputService.MouseDeltaSensitivity: float`:Scales the delta (change) output of the user's Mouse. - `UserInputService.MouseEnabled: boolean`:Describes whether the user's device has a mouse available. - `UserInputService.MouseIcon: ContentId`:The content ID of the image for the user's mouse icon. - `UserInputService.MouseIconContent: Content`:The content ID of the image for the user's mouse icon. Only supports asset URIs. - `UserInputService.MouseIconEnabled: boolean`:Determines whether the mouse icon is visible. - `UserInputService.OnScreenKeyboardPosition: Vector2`:Determines the position of the on-screen keyboard. - `UserInputService.OnScreenKeyboardSize: Vector2`:Determines the size of the on-screen keyboard. - `UserInputService.OnScreenKeyboardVisible: boolean`:Describes whether an on-screen keyboard is currently visible on the user's screen. - `UserInputService.PreferredInput: PreferredInput`:Queries the primary input type a player is using, based on anticipated user behavior. - `UserInputService.TouchEnabled: boolean`:タッチ操作ができる端末かどうか。 ## メソッド - `UserInputService:CreateVirtualInput(target: Instance): Object`:Creates a VirtualInput object for simulating mouse, keyboard, and pointer input. - `UserInputService:GamepadSupports(gamepadNum: UserInputType, gamepadKeyCode: KeyCode): boolean`:Returns whether the given UserInputType gamepad supports a button corresponding with the given KeyCode. - `UserInputService:GetConnectedGamepads(): Array`:Returns an array of UserInputType gamepads currently connected. - `UserInputService:GetDeviceAcceleration(): InputObject`:Returns an InputObject that describes the device's current acceleration. - `UserInputService:GetDeviceGravity(): InputObject`:Returns an InputObject describing the device's current gravity vector. - `UserInputService:GetDeviceRotation(): Tuple`:Returns an InputObject and a CFrame describing the device's current rotation vector. - `UserInputService:GetFocusedTextBox(): TextBox`:Returns the TextBox the client is currently focused on. - `UserInputService:GetGamepadConnected(gamepadNum: UserInputType): boolean`:Returns whether a gamepad with the given UserInputType is connected. - `UserInputService:GetGamepadState(gamepadNum: UserInputType): List`:Returns an array of Class.InputObject|InputObjects for all available inputs on the given gamepad, representing each input's last input state. - `UserInputService:GetImageForKeyCode(keyCode: KeyCode): ContentId`:Returns an image for the requested KeyCode. - `UserInputService:GetKeysPressed(): List`:Returns an array of Class.InputObject|InputObjects associated with the Enum.KeyCode|keys currently being pressed down. - `UserInputService:GetLastInputType(): UserInputType`:Returns the UserInputType associated with the user's most recent input. - `UserInputService:GetMouseButtonsPressed(): List`:Returns an array of Class.InputObject|InputObjects associated with the mouse buttons currently being held down. - `UserInputService: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. - `UserInputService:GetMouseLocation(): Vector2`:Returns the current screen location of the player's Mouse relative to the top-left corner of the screen. - `UserInputService:GetNavigationGamepads(): Array`:Returns an array of gamepads connected and enabled for GuiObject navigation in descending order of priority. - `UserInputService: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. - `UserInputService:GetSupportedGamepadKeyCodes(gamepadNum: UserInputType): Array`:Returns an array of Enum.KeyCode|KeyCodes that the gamepad associated with the given UserInputType supports. - `UserInputService:IsGamepadButtonDown(gamepadNum: UserInputType, gamepadKeyCode: KeyCode): boolean`:Determines whether a particular button is pressed on a gamepad. - `UserInputService:IsKeyDown(keyCode: KeyCode): boolean`:指定したキーが押されているかを調べます。 - `UserInputService:IsMouseButtonPressed(mouseButton: UserInputType): boolean`:Returns whether the given mouse button is currently held down. - `UserInputService:IsNavigationGamepad(gamepadEnum: UserInputType): boolean`:Returns true if the specified gamepad is allowed to control navigation and selection Class.GuiObject|GuiObjects. - `UserInputService:RecenterUserHeadCFrame(): ()`:Recenters the CFrame of the VR headset to the current orientation of the headset worn by the user. - `UserInputService:SetNavigationGamepad(gamepadEnum: UserInputType, enabled: boolean): ()`:Sets whether or not the specified gamepad can move the GuiObject navigator. ## イベント - `UserInputService.DeviceAccelerationChanged(acceleration: InputObject)`:Fires when a user moves a device that has an accelerometer. - `UserInputService.DeviceGravityChanged(gravity: InputObject)`:Fires when the force of gravity changes on a device that has an enabled accelerometer. - `UserInputService.DeviceRotationChanged(rotation: InputObject, cframe: CFrame)`:Fires when a user rotates a device that has a gyroscope. - `UserInputService.GamepadConnected(gamepadNum: UserInputType)`:Fires when a gamepad is connected to the client. - `UserInputService.GamepadDisconnected(gamepadNum: UserInputType)`:Fires when a gamepad is disconnected from the client. - `UserInputService.InputBegan(input: InputObject, gameProcessedEvent: boolean)`:キーを押す・クリックするなど、入力が始まったときに発生するイベントです。 - `UserInputService.InputChanged(input: InputObject, gameProcessedEvent: boolean)`:Fires when a user changes how they're interacting with an input device such as a mouse or gamepad. - `UserInputService.InputEnded(input: InputObject, gameProcessedEvent: boolean)`:入力が終わった(キーを離した)ときに発生するイベントです。 - `UserInputService.JumpRequest()`:Fires whenever the client makes a request for their character to jump. - `UserInputService.LastInputTypeChanged(lastInputType: UserInputType)`:Fires whenever the client's UserInputType is changed. - `UserInputService.PointerAction(wheel: float, pan: Vector2, pinch: float, gameProcessedEvent: boolean)`:Fires when the user performs a specific pointer action. - `UserInputService.TextBoxFocused(textboxFocused: TextBox)`:Fires when the client focuses on a TextBox. - `UserInputService.TextBoxFocusReleased(textboxReleased: TextBox)`:Fires when the client loses focus on a TextBox. - `UserInputService.TouchDrag(dragDirection: SwipeDirection, numberOfTouches: int, gameProcessedEvent: boolean)`:Fires when the user drags on the screen of a Class.UserInputService.TouchEnabled|TouchEnabled device. - `UserInputService.TouchEnded(touch: InputObject, gameProcessedEvent: boolean)`:Fires when a user releases their finger from the screen of a Class.UserInputService.TouchEnabled|TouchEnabled device. - `UserInputService.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. - `UserInputService.TouchMoved(touch: InputObject, gameProcessedEvent: boolean)`:Fires when a user moves their finger on the screen of a Class.UserInputService.TouchEnabled|TouchEnabled device. - `UserInputService.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. - `UserInputService.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. - `UserInputService.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. - `UserInputService.TouchStarted(touch: InputObject, gameProcessedEvent: boolean)`:Fires when a user places their finger on the screen of a Class.UserInputService.TouchEnabled|TouchEnabled device. - `UserInputService.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. - `UserInputService.TouchTap(touchPositions: Array, gameProcessedEvent: boolean)`:Fires when a user taps their finger on the screen of a Class.UserInputService.TouchEnabled|TouchEnabled device. - `UserInputService.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. - `UserInputService.WindowFocused()`:Fires when the window of the Roblox client gains focus on the user's screen. - `UserInputService.WindowFocusReleased()`:Fires when the window of the Roblox client loses focus on the user's screen. 英語の説明とメンバー一覧:Roblox Creator Documentation(CC BY 4.0)。日本語の解説はこのサイト独自のものです。 執筆:鈴木孝昌(現役プロジェクトマネージャー/プログラミング講師)/運営:沖縄マイクラ部 プログラミングスクール「クロスウェーブ」(https://minecraft-okinawa.com/)