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 從公開儲存庫中收錄這些內容。

檢舉或申請下架