roblox-input
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseWhen to Load
加载时机
Load when handling keyboard, mouse, gamepad, touch, accelerometer, or gyroscope input; binding actions across platforms; or detecting what input devices the player has. Client-only — both services require or client .
LocalScriptRunContext当处理键盘、鼠标、游戏手柄、触摸、加速度计或陀螺仪输入;跨平台绑定操作;或检测玩家拥有的输入设备时加载。仅适用于客户端——这两个服务都需要或客户端。
LocalScriptRunContextQuick Reference
快速参考
Core events (): , , fire as . does NOT fire for mouse wheel. Events only fire while the client window is focused.
UserInputServiceInputBeganInputChangedInputEnded(input: InputObject, gameProcessedEvent: boolean)InputBeganPlatform detection (cache at startup): , , , , , , , (the device the player is currently using most).
KeyboardEnabledMouseEnabledTouchEnabledGamepadEnabledAccelerometerEnabledGyroscopeEnabledVREnabledPreferredInputPolling queries (cheaper than events for held-state):
luau
UIS:IsKeyDown(Enum.KeyCode.W)
UIS:IsMouseButtonPressed(Enum.UserInputType.MouseButton1)
UIS:IsGamepadButtonDown(Enum.UserInputType.Gamepad1, Enum.KeyCode.ButtonA)
local dx, dy = UIS:GetMouseDelta()Prefer over for gameplay — free conflict resolution (chat won't steal H) and free mobile buttons:
ContextActionServiceInputBeganluau
local CAS = game:GetService("ContextActionService")
local function onAction(name, state, _input)
if name == "Jump" and state == Enum.UserInputState.Begin then
humanoid.Jump = true
end
end
CAS:BindAction("Jump", onAction, true,
Enum.KeyCode.Space, Enum.KeyCode.ButtonA)BindAction(name, handler, createTouchButton, ...inputTypes)ContextActionResult.Sink.PassTouch buttons: auto-creates an under (max 7). Customize via → ///.
createTouchButton=trueImageButtonPlayerGui.ContextActionGui.ContextButtonFrameCAS:GetButton(name)SetTitleSetImageSetPositionSetDescriptionGamepad: → ... Listen to /.
GetConnectedGamepads()Gamepad1Gamepad8GamepadConnectedDisconnectedTouch gestures: , (world pos), , , , , , . Raw: //.
TouchTapTouchTapInWorldTouchPanTouchPinchTouchRotateTouchSwipeTouchLongPressTouchDragTouchStartedTouchMovedTouchEndedPitfalls:
- in InputBegan → UI consumed it. Filter for gameplay.
gameProcessedEvent=true - is stack-based: most-recent wins. Use
BindAction.BindActionAtPriority - Client-only. Server scripts silently no-op.
- fires multiple times per jump — debounce.
JumpRequest - Mouse wheel only fires .
InputChanged
See for full event tables, , mobile buttons, sensors.
references/full.mdContextActionResult核心事件():、、会以的形式触发。不会对鼠标滚轮触发。仅当客户端窗口处于焦点状态时,事件才会触发。
UserInputServiceInputBeganInputChangedInputEnded(input: InputObject, gameProcessedEvent: boolean)InputBegan平台检测(启动时缓存):、、、、、、、(玩家当前最常使用的设备)。
KeyboardEnabledMouseEnabledTouchEnabledGamepadEnabledAccelerometerEnabledGyroscopeEnabledVREnabledPreferredInput轮询查询(对于持续按下状态,比事件更高效):
luau
UIS:IsKeyDown(Enum.KeyCode.W)
UIS:IsMouseButtonPressed(Enum.UserInputType.MouseButton1)
UIS:IsGamepadButtonDown(Enum.UserInputType.Gamepad1, Enum.KeyCode.ButtonA)
local dx, dy = UIS:GetMouseDelta()对于游戏玩法,优先使用而非——免费提供冲突解决(聊天不会占用H键)和免费移动按钮:
ContextActionServiceInputBeganluau
local CAS = game:GetService("ContextActionService")
local function onAction(name, state, _input)
if name == "Jump" and state == Enum.UserInputState.Begin then
humanoid.Jump = true
end
end
CAS:BindAction("Jump", onAction, true,
Enum.KeyCode.Space, Enum.KeyCode.ButtonA)BindAction(name, handler, createTouchButton, ...inputTypes)ContextActionResult.Sink.Pass触摸按钮:会在下自动创建一个(最多7个)。可通过调用///进行自定义。
createTouchButton=truePlayerGui.ContextActionGui.ContextButtonFrameImageButtonCAS:GetButton(name)SetTitleSetImageSetPositionSetDescription游戏手柄:返回..。监听/事件。
GetConnectedGamepads()Gamepad1Gamepad8GamepadConnectedDisconnected触摸手势:、(世界坐标)、、、、、、。原始事件://。
TouchTapTouchTapInWorldTouchPanTouchPinchTouchRotateTouchSwipeTouchLongPressTouchDragTouchStartedTouchMovedTouchEnded注意事项:
- 中的
InputBegan表示UI已消费该输入。游戏玩法中需过滤此类情况。gameProcessedEvent=true - 基于栈结构:最近绑定的获胜。使用
BindAction来设置优先级。BindActionAtPriority - 仅适用于客户端。服务器脚本会静默无操作。
- 每次跳跃会触发多次——需要防抖处理。
JumpRequest - 鼠标滚轮仅触发事件。
InputChanged
完整事件表、、移动按钮、传感器相关内容请查看。
ContextActionResultreferences/full.md