Roblox Input

TabooHarmony/roblox-brain/skills/gameplay/roblox-input

作者 TabooHarmony38826be57ee37bcf023e9c2b85681bea3909281c无许可证收录于 2026年10月9日更新于 2026年10月9日

Use when handling Roblox keyboard, mouse, gamepad, touch, motion input, or cross-platform action binding.

AI 生成的概览

关于处理 Roblox 键盘、鼠标、手柄、触摸与体感输入以及跨平台动作绑定的参考指南。

功能
提供 Roblox 输入处理的参考指导:UserInputService 事件、ContextActionService 动作绑定、Server Authority 输入动作、手柄焦点、触摸手势与拖拽检测器。其中列出常见陷阱,例如 gameProcessedEvent 过滤、绑定优先级以及仅限客户端执行。并指向更完整的参考文件以查阅事件表与轮询方法。
适用场景
适用于编写或审查 Roblox 客户端键盘、鼠标、手柄、触摸或体感输入代码,或需要跨平台绑定动作时。当输入需要影响 Server Authority 模拟时同样适用。
运行要求
不含脚本,仅为说明文档。需要 Roblox 开发环境(Luau、Roblox Studio),并可访问随附的参考文件。

Roblox Input

When to Load

Load for keyboard, mouse, gamepad, touch, motion, or cross-platform action binding. Client-side only. For simulation-affecting input in a Server Authority project, use the Input Action System rather than traditional input events.

Quick Reference

Core events (UserInputService): InputBegan, InputChanged, InputEnded fire as (input: InputObject, gameProcessedEvent: boolean). InputBegan does NOT fire for mouse wheel. Events only fire while the client window is focused.

Prefer ContextActionService over InputBegan for gameplay: free conflict resolution (chat won't steal H) and free mobile buttons:

luau
local CAS = game:GetService("ContextActionService")
local function onAction(name, state, _input)    if name == "Jump" and state == Enum.UserInputState.Begin then        humanoid.Jump = true    endend
CAS:BindAction("Jump", onAction, true,    Enum.KeyCode.Space, Enum.KeyCode.ButtonA)

BindAction(name, handler, createTouchButton, ...inputTypes). Handler returns ContextActionResult.Sink to consume, .Pass to fall through.

Server Authority: use InputAction/InputContext for inputs that affect the core simulation, store the input state where the synchronized simulation can read it, and process it through RunService:BindToSimulation() (requires Workspace.UseFixedSimulation enabled in Studio). ContextActionService remains appropriate for UI-only or classic-project actions.

Gamepad UI focus: separate gameplay bindings from menu selection. Set GuiService.SelectedObject, mark controls Selectable, and test nested/modal navigation.

Gamepad: use GetConnectedGamepads() and listen to connection changes.

Touch: use high-level gesture events or raw TouchStarted/TouchMoved/TouchEnded when tracking fingers.

Dragging: DragDetector (3D parts/models, physics-capable) and UIDragDetector (UI) make objects draggable with zero code; events DragStart/DragContinue/DragEnd.

Pitfalls:

  • gameProcessedEvent=true in InputBegan → UI consumed it. Filter for gameplay.
  • BindAction is stack-based: most-recent wins. Use BindActionAtPriority.
  • Client-only. Server scripts silently no-op.
  • JumpRequest fires multiple times per jump; debounce.
  • Mouse wheel only fires InputChanged.

Full event tables and polling methods: references/full.md.

来源与署名

来源:TabooHarmony/roblox-brain位于skills/gameplay/roblox-input提交38826be

许可证: 无许可证

内容归原作者所有。SourceWeft 从公开仓库中收录这些内容。

举报或申请下架