学ぶ
エンジンクラス
UserInputService
作成できません
サービス
複製されていません

*このコンテンツは、ベータ版のAI(人工知能)を使用して翻訳されており、エラーが含まれている可能性があります。このページを英語で表示するには、 こちら をクリックしてください。


概要
イベント
InputBegan(input: InputObject,gameProcessedEvent: boolean):RBXScriptSignal
InputChanged(input: InputObject,gameProcessedEvent: boolean):RBXScriptSignal
InputEnded(input: InputObject,gameProcessedEvent: boolean):RBXScriptSignal
PointerAction(wheel: number,pan: Vector2,pinch: number,gameProcessedEvent: boolean):RBXScriptSignal
TouchDrag(dragDirection: Enum.SwipeDirection,numberOfTouches: number,gameProcessedEvent: boolean):RBXScriptSignal
TouchEnded(touch: InputObject,gameProcessedEvent: boolean):RBXScriptSignal
TouchLongPress(touchPositions: {any},state: Enum.UserInputState,gameProcessedEvent: boolean):RBXScriptSignal
TouchMoved(touch: InputObject,gameProcessedEvent: boolean):RBXScriptSignal
TouchPan(touchPositions: {any},totalTranslation: Vector2,velocity: Vector2,state: Enum.UserInputState,gameProcessedEvent: boolean):RBXScriptSignal
TouchPinch(touchPositions: {any},scale: number,velocity: number,state: Enum.UserInputState,gameProcessedEvent: boolean):RBXScriptSignal
TouchRotate(touchPositions: {any},rotation: number,velocity: number,state: Enum.UserInputState,gameProcessedEvent: boolean):RBXScriptSignal
TouchStarted(touch: InputObject,gameProcessedEvent: boolean):RBXScriptSignal
TouchSwipe(swipeDirection: Enum.SwipeDirection,numberOfTouches: number,gameProcessedEvent: boolean):RBXScriptSignal
TouchTap(touchPositions: {any},gameProcessedEvent: boolean):RBXScriptSignal
継承されたメンバー

APIリファレンス
プロパティ
AccelerometerEnabled
読み取り専用
複製されていません
並列読み取り
機能: Input
UserInputService.AccelerometerEnabled:boolean
コードサンプル
加速度センサーを使用してボールを移動させる
local Workspace = game:GetService("Workspace")
local UserInputService = game:GetService("UserInputService")
local ball = script.Parent:WaitForChild("Ball")
local mass = ball:GetMass()
local gravityForce = ball:WaitForChild("GravityForce")
local function moveBall(gravity)
gravityForce.Force = gravity.Position * Workspace.Gravity * mass
end
if UserInputService.AccelerometerEnabled then
UserInputService.DeviceGravityChanged:Connect(moveBall)
end

GamepadEnabled
読み取り専用
複製されていません
並列読み取り
機能: Input
UserInputService.GamepadEnabled:boolean

GyroscopeEnabled
読み取り専用
複製されていません
並列読み取り
機能: Input
UserInputService.GyroscopeEnabled:boolean

KeyboardEnabled
読み取り専用
複製されていません
並列読み取り
機能: Input
UserInputService.KeyboardEnabled:boolean

ModalEnabled
非推奨

MouseBehavior
並列読み取り
機能: Input
UserInputService.MouseBehavior:Enum.MouseBehavior

MouseDeltaSensitivity
複製されていません
並列読み取り
機能: Input
UserInputService.MouseDeltaSensitivity:number

MouseEnabled
読み取り専用
複製されていません
並列読み取り
機能: Input
UserInputService.MouseEnabled:boolean

MouseIcon
並列読み取り
機能: Input
UserInputService.MouseIcon:ContentId
コードサンプル
カスタムマウスアイコン
local UserInputService = game:GetService("UserInputService")
-- カーソルを以前に設定したものに戻すには、変数に保存する必要があります
local savedCursor = nil
local function setTemporaryCursor(cursor: string)
-- 現在保存されていない場合のみ保存されたカーソルを更新します
if not savedCursor then
savedCursor = UserInputService.MouseIcon
end
UserInputService.MouseIcon = cursor
end
local function clearTemporaryCursor()
-- 保存されたカーソルがある場合のみマウスカーソルを復元します
if savedCursor then
UserInputService.MouseIcon = savedCursor
-- 同じカーソルを二度復元しないようにします(他のスクリプトを上書きする可能性があります)
savedCursor = nil
end
end
setTemporaryCursor("http://www.roblox.com/asset?id=163023520")
print(UserInputService.MouseIcon)
clearTemporaryCursor()

MouseIconContent
並列読み取り
機能: Input
UserInputService.MouseIconContent:Content
コードサンプル
カスタムマウスアイコン
local UserInputService = game:GetService("UserInputService")
-- カーソルを以前に設定したものに戻すには、変数に保存する必要があります
local savedCursor = nil
local function setTemporaryCursor(cursor: string)
-- 現在保存されていない場合のみ保存されたカーソルを更新します
if not savedCursor then
savedCursor = UserInputService.MouseIcon
end
UserInputService.MouseIcon = cursor
end
local function clearTemporaryCursor()
-- 保存されたカーソルがある場合のみマウスカーソルを復元します
if savedCursor then
UserInputService.MouseIcon = savedCursor
-- 同じカーソルを二度復元しないようにします(他のスクリプトを上書きする可能性があります)
savedCursor = nil
end
end
setTemporaryCursor("http://www.roblox.com/asset?id=163023520")
print(UserInputService.MouseIcon)
clearTemporaryCursor()

MouseIconEnabled
並列読み取り
機能: Input
UserInputService.MouseIconEnabled:boolean

OnScreenKeyboardPosition
読み取り専用
複製されていません
並列読み取り
機能: Input
UserInputService.OnScreenKeyboardPosition:Vector2

OnScreenKeyboardSize
読み取り専用
複製されていません
並列読み取り
機能: Input
UserInputService.OnScreenKeyboardSize:Vector2

OnScreenKeyboardVisible
読み取り専用
複製されていません
並列読み取り
機能: Input
UserInputService.OnScreenKeyboardVisible:boolean

PreferredInput
読み取り専用
複製されていません
並列読み取り
機能: Input
UserInputService.PreferredInput:Enum.PreferredInput
コードサンプル
優先入力検出
local UserInputService = game:GetService("UserInputService")
local function preferredInputChanged()
local preferredInput = UserInputService.PreferredInput
if preferredInput == Enum.PreferredInput.Touch then
-- プレイヤーは他の入力タイプが利用できない/接続されていないタッチ対応デバイスを使用しています
print("タッチ")
elseif preferredInput == Enum.PreferredInput.Gamepad then
-- プレイヤーが接続したか、最近ゲームパッドと対話しました
print("ゲームパッド")
elseif preferredInput == Enum.PreferredInput.KeyboardAndMouse then
-- プレイヤーが接続したか、最近キーボードまたはマウスと対話しました
print("キーボードとマウス")
end
end
preferredInputChanged()
UserInputService:GetPropertyChangedSignal("PreferredInput"):Connect(function()
preferredInputChanged()
end)

TouchEnabled
読み取り専用
複製されていません
並列読み取り
機能: Input
UserInputService.TouchEnabled:boolean

TouchScreenEnabled
読み取り専用
複製されていません
Robloxのスクリプトセキュリティ
並列読み取り
機能: Input
UserInputService.TouchScreenEnabled:boolean

UserHeadCFrame
非推奨

VREnabled
非推奨

方法
CreateVirtualInput
機能: Input
UserInputService:CreateVirtualInput():Object
戻り値

GamepadSupports
機能: Input
UserInputService:GamepadSupports(
gamepadNum:Enum.UserInputType, gamepadKeyCode:Enum.KeyCode
パラメータ
gamepadKeyCode:Enum.KeyCode
戻り値

GetConnectedGamepads
機能: Input
UserInputService:GetConnectedGamepads():{any}
戻り値

GetDeviceAcceleration
機能: Input
UserInputService:GetDeviceAcceleration():InputObject
戻り値
コードサンプル
出力デバイスの加速度
local UserInputService = game:GetService("UserInputService")
if UserInputService.AccelerometerEnabled then
local acceleration = UserInputService:GetDeviceAcceleration().Position
print(acceleration)
else
warn("デバイスに有効な加速度計がないため、デバイスの加速度を取得できません!")
end

GetDeviceGravity
機能: Input
UserInputService:GetDeviceGravity():InputObject
戻り値
コードサンプル
ジャイロスコープでオブジェクトを動かす
local UserInputService = game:GetService("UserInputService")
local bubble = script.Parent:WaitForChild("Bubble")
local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = CFrame.new(0, 20, 0) * CFrame.Angles(-math.pi / 2, 0, 0)
if UserInputService.GyroscopeEnabled then
-- ジャイロスコープが変化を検出した際にイベントをバインドする
UserInputService.DeviceGravityChanged:Connect(function(accel)
-- ジャイロスコープデータに基づいてバブルを世界で移動する
bubble.Position = Vector3.new(-8 * accel.Position.X, 1.8, -8 * accel.Position.Z)
end)
end

GetDeviceRotation
機能: Input
UserInputService:GetDeviceRotation():Tuple
戻り値
コードサンプル
出力デバイスの回転
local UserInputService = game:GetService("UserInputService")
if UserInputService.GyroscopeEnabled then
local _, cf = UserInputService:GetDeviceRotation()
print(cf)
else
warn("デバイスに有効なジャイロスコープがないため、デバイスの回転を取得できません!")
end

GetFocusedTextBox
機能: Input
UserInputService:GetFocusedTextBox():TextBox
戻り値

GetGamepadConnected
機能: Input
UserInputService:GetGamepadConnected(gamepadNum:Enum.UserInputType):boolean
パラメータ
戻り値

GetGamepadState
機能: Input
UserInputService:GetGamepadState(gamepadNum:Enum.UserInputType):{InputObject}
パラメータ
戻り値

GetImageForKeyCode
機能: Input
UserInputService:GetImageForKeyCode(keyCode:Enum.KeyCode):ContentId
パラメータ
keyCode:Enum.KeyCode
戻り値
ContentId
コードサンプル
UserInputService - キーコードに対する画像を取得
local UserInputService = game:GetService("UserInputService")
local imageLabel = script.Parent
local key = Enum.KeyCode.ButtonA
local mappedIconImage = UserInputService:GetImageForKeyCode(key)
imageLabel.Image = mappedIconImage

GetKeysPressed
機能: Input
UserInputService:GetKeysPressed():{InputObject}
戻り値

GetLastInputType
機能: Input
UserInputService:GetLastInputType():Enum.UserInputType
コードサンプル
最後の入力タイプを検出
local UserInputService = game:GetService("UserInputService")
if UserInputService:GetLastInputType() == Enum.UserInputType.Keyboard then
print("最新の入力はキーボードでした!")
end

GetMouseButtonsPressed
機能: Input
UserInputService:GetMouseButtonsPressed():{InputObject}
戻り値
コードサンプル
押されたマウスボタンを確認する
local UserInputService = game:GetService("UserInputService")
UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
-- 押されたマウスボタンの配列を返す
local buttonsPressed = UserInputService:GetMouseButtonsPressed()
local m1, m2 = false, false
for _, button in buttonsPressed do
if button.UserInputType == Enum.UserInputType.MouseButton1 then
print("MouseButton1 が押されました!")
m1 = true
end
if button.UserInputType == Enum.UserInputType.MouseButton2 then
print("MouseButton2 が押されました!")
m2 = true
end
if m1 and m2 then
print("両方のマウスボタンが押されました!")
end
end
end)

GetMouseDelta
機能: Input
UserInputService:GetMouseDelta():Vector2
戻り値
コードサンプル
マウスデルタの取得
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
local function onRenderStep()
local delta = UserInputService:GetMouseDelta()
if delta ~= Vector2.new(0, 0) then
print("マウスが移動しました", delta, "最後のステップから")
end
end
RunService:BindToRenderStep("MeasureMouseMovement", Enum.RenderPriority.Input.Value, onRenderStep)

GetMouseLocation
機能: Input
UserInputService:GetMouseLocation():Vector2
戻り値

GetNavigationGamepads
機能: Input
UserInputService:GetNavigationGamepads():{any}
戻り値

GetStringForKeyCode
機能: Input
UserInputService:GetStringForKeyCode(
パラメータ
keyCode:Enum.KeyCode
既定値: "Default"
戻り値

GetSupportedGamepadKeyCodes
機能: Input
UserInputService:GetSupportedGamepadKeyCodes(gamepadNum:Enum.UserInputType):{any}
パラメータ
戻り値

GetUserCFrame
非推奨

IsGamepadButtonDown
機能: Input
UserInputService:IsGamepadButtonDown(
gamepadNum:Enum.UserInputType, gamepadKeyCode:Enum.KeyCode
パラメータ
gamepadKeyCode:Enum.KeyCode
戻り値

IsKeyDown
機能: Input
UserInputService:IsKeyDown(keyCode:Enum.KeyCode):boolean
パラメータ
keyCode:Enum.KeyCode
戻り値

IsMouseButtonPressed
機能: Input
UserInputService:IsMouseButtonPressed(mouseButton:Enum.UserInputType):boolean
パラメータ
mouseButton:Enum.UserInputType
戻り値

IsNavigationGamepad
機能: Input
UserInputService:IsNavigationGamepad(gamepadEnum:Enum.UserInputType):boolean
パラメータ
gamepadEnum:Enum.UserInputType
戻り値

RecenterUserHeadCFrame
機能: Input
UserInputService:RecenterUserHeadCFrame():()
戻り値
()

SetNavigationGamepad
機能: Input
UserInputService:SetNavigationGamepad(
gamepadEnum:Enum.UserInputType, enabled:boolean
):()
パラメータ
gamepadEnum:Enum.UserInputType
enabled:boolean
戻り値
()

イベント
DeviceAccelerationChanged
機能: Input
UserInputService.DeviceAccelerationChanged(acceleration:InputObject):RBXScriptSignal
パラメータ
acceleration:InputObject
コードサンプル
加速度センサを使用してプレイヤーを制御
local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
local SENSITIVITY = 0.2
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local ready = true
local function changeAcceleration(acceleration)
if ready then
ready = false
local accel = acceleration.Position
if accel.Y >= SENSITIVITY then
humanoid.Jump = true
end
if accel.Z <= -SENSITIVITY then
humanoid:Move(Vector3.new(-1, 0, 0))
end
if accel.Z >= SENSITIVITY then
humanoid:Move(Vector3.new(1, 0, 0))
end
if accel.X <= -SENSITIVITY then
humanoid:Move(Vector3.new(0, 0, 1))
end
if accel.X >= SENSITIVITY then
humanoid:Move(Vector3.new(0, 0, -1))
end
task.wait(1)
ready = true
end
end
if UserInputService.AccelerometerEnabled then
UserInputService.DeviceAccelerationChanged:Connect(changeAcceleration)
end

DeviceGravityChanged
機能: Input
UserInputService.DeviceGravityChanged(gravity:InputObject):RBXScriptSignal
パラメータ
gravity:InputObject
コードサンプル
加速度センサーを使用してボールを移動させる
local Workspace = game:GetService("Workspace")
local UserInputService = game:GetService("UserInputService")
local ball = script.Parent:WaitForChild("Ball")
local mass = ball:GetMass()
local gravityForce = ball:WaitForChild("GravityForce")
local function moveBall(gravity)
gravityForce.Force = gravity.Position * Workspace.Gravity * mass
end
if UserInputService.AccelerometerEnabled then
UserInputService.DeviceGravityChanged:Connect(moveBall)
end

DeviceRotationChanged
機能: Input
UserInputService.DeviceRotationChanged(
rotation:InputObject, cframe:CFrame
パラメータ
rotation:InputObject
cframe:CFrame

GamepadConnected
機能: Input
UserInputService.GamepadConnected(gamepadNum:Enum.UserInputType):RBXScriptSignal
パラメータ

GamepadDisconnected
機能: Input
UserInputService.GamepadDisconnected(gamepadNum:Enum.UserInputType):RBXScriptSignal
パラメータ

InputBegan
機能: Input
UserInputService.InputBegan(
input:InputObject, gameProcessedEvent:boolean
パラメータ
gameProcessedEvent:boolean

InputChanged
機能: Input
UserInputService.InputChanged(
input:InputObject, gameProcessedEvent:boolean
パラメータ
gameProcessedEvent:boolean

InputEnded
機能: Input
UserInputService.InputEnded(
input:InputObject, gameProcessedEvent:boolean
パラメータ
gameProcessedEvent:boolean

JumpRequest
機能: Input
UserInputService.JumpRequest():RBXScriptSignal
コードサンプル
デフォルトのジャンプを無効にする
local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
local processJumpRequest = false
local COOLDOWN_TIME = 0.5
local function jumpRequest()
if processJumpRequest == false then
processJumpRequest = true
-- カスタムジャンプリクエストを処理する
print("ジャンプが要求されました!")
-- クールダウン後にデバウンス変数をリセットする
task.wait(COOLDOWN_TIME)
processJumpRequest = false
end
end
UserInputService.JumpRequest:Connect(jumpRequest)

LastInputTypeChanged
機能: Input
UserInputService.LastInputTypeChanged(lastInputType:Enum.UserInputType):RBXScriptSignal
パラメータ
lastInputType:Enum.UserInputType

PointerAction
機能: Input
UserInputService.PointerAction(
wheel:number, pan:Vector2, pinch:number, gameProcessedEvent:boolean
パラメータ
wheel:number
pinch:number
gameProcessedEvent:boolean

TextBoxFocused
機能: Input
UserInputService.TextBoxFocused(textboxFocused:TextBox):RBXScriptSignal
パラメータ
textboxFocused:TextBox
コードサンプル
フォーカス時のテキストボックスの修正
local UserInputService = game:GetService("UserInputService")
local function textBoxFocused(textBox)
textBox.BackgroundTransparency = 0
end
local function textBoxFocusReleased(textBox)
textBox.BackgroundTransparency = 0.5
end
UserInputService.TextBoxFocused:Connect(textBoxFocused)
UserInputService.TextBoxFocusReleased:Connect(textBoxFocusReleased)

TextBoxFocusReleased
機能: Input
UserInputService.TextBoxFocusReleased(textboxReleased:TextBox):RBXScriptSignal
パラメータ
textboxReleased:TextBox
コードサンプル
フォーカス時のテキストボックスの修正
local UserInputService = game:GetService("UserInputService")
local function textBoxFocused(textBox)
textBox.BackgroundTransparency = 0
end
local function textBoxFocusReleased(textBox)
textBox.BackgroundTransparency = 0.5
end
UserInputService.TextBoxFocused:Connect(textBoxFocused)
UserInputService.TextBoxFocusReleased:Connect(textBoxFocusReleased)

TouchDrag
機能: Input
UserInputService.TouchDrag(
dragDirection:Enum.SwipeDirection, numberOfTouches:number, gameProcessedEvent:boolean
パラメータ
dragDirection:Enum.SwipeDirection
numberOfTouches:number
gameProcessedEvent:boolean

TouchEnded
機能: Input
UserInputService.TouchEnded(
touch:InputObject, gameProcessedEvent:boolean
パラメータ
gameProcessedEvent:boolean

TouchLongPress
機能: Input
UserInputService.TouchLongPress(
touchPositions:{any}, state:Enum.UserInputState, gameProcessedEvent:boolean
パラメータ
touchPositions:{any}
gameProcessedEvent:boolean

TouchMoved
機能: Input
UserInputService.TouchMoved(
touch:InputObject, gameProcessedEvent:boolean
パラメータ
gameProcessedEvent:boolean

TouchPan
機能: Input
UserInputService.TouchPan(
touchPositions:{any}, totalTranslation:Vector2, velocity:Vector2, state:Enum.UserInputState, gameProcessedEvent:boolean
パラメータ
touchPositions:{any}
totalTranslation:Vector2
velocity:Vector2
gameProcessedEvent:boolean

TouchPinch
機能: Input
UserInputService.TouchPinch(
touchPositions:{any}, scale:number, velocity:number, state:Enum.UserInputState, gameProcessedEvent:boolean
パラメータ
touchPositions:{any}
scale:number
velocity:number
gameProcessedEvent:boolean

TouchRotate
機能: Input
UserInputService.TouchRotate(
touchPositions:{any}, rotation:number, velocity:number, state:Enum.UserInputState, gameProcessedEvent:boolean
パラメータ
touchPositions:{any}
rotation:number
velocity:number
gameProcessedEvent:boolean

TouchStarted
機能: Input
UserInputService.TouchStarted(
touch:InputObject, gameProcessedEvent:boolean
パラメータ
gameProcessedEvent:boolean

TouchSwipe
機能: Input
UserInputService.TouchSwipe(
swipeDirection:Enum.SwipeDirection, numberOfTouches:number, gameProcessedEvent:boolean
パラメータ
swipeDirection:Enum.SwipeDirection
numberOfTouches:number
gameProcessedEvent:boolean

TouchTap
機能: Input
UserInputService.TouchTap(
touchPositions:{any}, gameProcessedEvent:boolean
パラメータ
touchPositions:{any}
gameProcessedEvent:boolean

TouchTapInWorld
機能: Input
UserInputService.TouchTapInWorld(
position:Vector2, processedByUI:boolean
パラメータ
position:Vector2
processedByUI:boolean

UserCFrameChanged
非推奨

WindowFocused
機能: Input
UserInputService.WindowFocused():RBXScriptSignal

WindowFocusReleased
機能: Input
UserInputService.WindowFocusReleased():RBXScriptSignal
コードサンプル
ウィンドウフォーカス解除スクリプト (LocalScript)
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local awayEvent = ReplicatedStorage:WaitForChild("AwayEvent")
local function focusGained()
awayEvent:FireServer(false)
end
local function focusReleased()
awayEvent:FireServer(true)
end
UserInputService.WindowFocused:Connect(focusGained)
UserInputService.WindowFocusReleased:Connect(focusReleased)
ウィンドウフォーカスアウェイスクリプト (スクリプト)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local awayEvent = Instance.new("RemoteEvent")
awayEvent.Name = "AwayEvent"
awayEvent.Parent = ReplicatedStorage
local function manageForceField(player, away)
if away then
local forceField = Instance.new("ForceField")
forceField.Parent = player.Character
else
local forceField = player.Character:FindFirstChildOfClass("ForceField")
if forceField then
forceField:Destroy()
end
end
end
awayEvent.OnServerEvent:Connect(manageForceField)

©2026 Roblox Corporation。Roblox(ロブロックス)、RobloxロゴおよびPowering Imaginationは、米国並びにその他の国における登録商標および非登録商標です。