360 Secure SkillHub
360 安全技能中心

roblox-input

该 Skill 以清单形式说明 Roblox 触控、手柄、键鼠和 TV 遥控输入中的常见陷阱与修复方法,涵盖按键冲突、菜单焦点、SurfaceGui 点击、Input Action System 迁移及测试建议,适合构建、修复或审查输入相关代码。

分类:开发
TabooHarmony
热度 17.14
最近更新 2026-12-01 11:24:36

安装

发给 Agent
帮我安装这个技能:npx secure-skills-cli add tabooharmony/roblox-brain/roblox-input
兼容性
通用兼容
联网要求
不联网
数据出网
数据不出本机
Metadata
name
roblox-input
description
Use when building, fixing or reviewing Roblox input: touch, gamepad, keyboard/mouse, action buttons, key binds, Input Action System.
when_to_use
Also when a button fires by accident, controls don't work on mobile or console, a controller gets stuck in a menu, a prompt shows the wrong key, the cursor is trapped in a menu, a key bind conflicts with Roblox, or SurfaceGui buttons don't click.
last_reviewed
"2026-11-28T00:00:00.000Z"
sources
["original","https://create.roblox.com/docs/input/input-action-system","https://create.roblox.com/docs/input/micro-gamepad","https://create.roblox.com/docs/input/gamepad","https://create.roblox.com/docs/players/disable-ui","https://create.roblox.com/docs/reference/engine/classes/UserInputService","https://create.roblox.com/docs/reference/engine/enums/PreferredInput","https://create.roblox.com/docs/reference/engine/classes/ContextActionService","https://create.roblox.com/docs/reference/engine/classes/InputContext","https://create.roblox.com/docs/reference/engine/classes/InputAction","https://create.roblox.com/docs/reference/engine/classes/InputBinding","https://create.roblox.com/docs/reference/engine/classes/InputActionLabel","https://create.roblox.com/docs/reference/engine/classes/SurfaceGui","https://create.roblox.com/docs/reference/engine/classes/ProximityPrompt","https://create.roblox.com/docs/reference/engine/classes/Tool","https://create.roblox.com/docs/production/publishing/console-guidelines","https://create.roblox.com/docs/projects/server-authority"]

Roblox Input

When to Load

Handling touch, gamepad, keyboard/mouse or TV-remote input: binds, on-screen action buttons, cancel paths, button hints. Layout, safe areas, touch-button placement from TouchGui and gamepad focus graphs: roblox-ui (§1, §2); aim and shoulder cameras: roblox-camera; sending input to the server: roblox-networking.

"Field case" = seen in one of the owner's projects; verify on your content.

Traps and review checklist (symptom -> cause -> fix)

  • Key bind does nothing or opens a Roblox panel -> it collides with a default bind. Always reserved: Esc/ButtonStart (Roblox menu), F9, F11, F12, PrintScreen. Reserved unless you disable the feature: / chat, Tab player list (CoreGuiType.PlayerList), backquote backpack, 0-9 tool equip, Backspace drop tool, \ UI selection, Shift mouse lock (EnableMouseLockOption); gamepad ButtonL1/ButtonR1 swap tools, ButtonR2 uses the tool, ButtonSelect UI selection. Never put a core feature on backquote (missing on many layouts), and every keyboard-opened panel also needs a tap button for touch (field case) (§1).
  • Interactive SurfaceGui buttons ignore clicks -> the SurfaceGui must live under PlayerGui (Adornee = the part), and the adorned part needs CanQuery = true, or input never reaches the button. Mounting it right is not enough if the sign part is CanQuery = false.
  • Cursor trapped in a menu in first person / shift-lock -> a visible GuiButton with Modal = true overrides MouseBehavior (unless right mouse is held), but the icon can stay hidden and per-frame camera code re-locks it. Set MouseIconEnabled = true too, drive both from one "any menu open" state that the camera code also reads (per-screen mouse code left invisible cursors and locked cameras, field case, repeated), restore on close, and close with a key and gamepad B (§1).
  • Clicks dropped near a proximity prompt in a locked-mouse game -> ClickablePrompt = true (default) puts the prompt button under the centred cursor; it sinks MouseButton1 (gameProcessedEvent = true) and drops held actions (field case). Set ClickablePrompt = false when the prompt is created (in PromptShown was too late); tap still works on mobile per the docs.
  • Touch buttons show on a PC, or stay after plugging in a pad -> layout picked once from TouchEnabled. Show controls from UserInputService.PreferredInput and re-run on GetPropertyChangedSignal("PreferredInput"). GetLastInputType() flips on every input and reports Focus on window focus; don't drive layout from it.
  • TV remote not detected -> Enum.PreferredInput.MicroGamepad exists but is not set yet for these devices . Check Gamepad1 connected and GamepadSupports false for both Thumbstick1 and Thumbstick2 (ButtonCenter too for a TV remote). Never detect by keycode: centre arrives as ButtonA, back as ButtonB, arrows as D-pad in menus but Thumbstick1/Thumbstick2 in gameplay, same as a full pad.
  • Controller stuck in a menu -> the gamepad button that opened the menu is still bound and swallows navigation. Menu binds must Pass (or their context be disabled) while any window is open; the D-pad that opened a window can't close it (it moves focus there), so close with B. Third-party top-bar libraries may listen on raw InputBegan for D-pad Up. Focus graph: roblox-ui §2.
  • Attack fires under a menu, or jump dead after closing one on gamepad -> gate every gameplay handler on one check: gameProcessedEvent, GetFocusedTextBox() == nil, not GuiService.MenuIsOpen, GuiService.SelectedObject == nil, no game window open. CAS handlers get no gameProcessedEvent.
  • Charged throw fires when the player cancelled -> cancel is not release. Cancel (never complete) on UserInputState.Cancel, window open, unequip/death, WindowFocusReleased, a PreferredInput change, or GamepadDisconnected of the pad that started the hold (poll that pad, not Gamepad1). CAS delivers End/Cancel (and touch-button input) with KeyCode.Unknown: branch on state before any keycode filter.
  • Gamepad R2 stopped firing the tool -> Tool.ManualActivationOnly = true also kills the BindActivate route the default controls use for ButtonR2. Set it from PreferredInput, not TouchEnabled.
  • Gamepad/touch shots go to a stale point -> aim code reads GetMouseLocation(). With PreferredInput not KeyboardAndMouse or the mouse locked, aim from the viewport centre and show the reticle (roblox-camera).
  • Wrong glyph or "Press 1" on console -> hardcoded key names. Use GetStringForKeyCode(key, Enum.KeyCodeStringFormat.Abbreviated) / GetImageForKeyCode(key) (separate PlayStation and Xbox image sets; Studio emulation returned PlayStation in a field case) or InputActionLabel; refresh on PreferredInput change, including tooltips and tutorial text. Hotbar cycles on ButtonL1/ButtonR1, not number hints.
  • Feels like auto-fire -> presses refused during cooldown are queued. Act only on a press that arrives when ready; clear the queued flag on every refused press.
  • Gadget runs forever after equip -> hold-to-run is a toggle on touch/gamepad (correct: the thumb also steers) but a trigger already down at equip lands its release in the toggle path. Clear the held flag on equip and unequip.
  • Move vector reads nothing -> Workspace.PlayerScriptsUseInputActionSystem (Studio property) makes the default controls run through input actions; code requiring PlayerScripts.PlayerModule for the move vector gets nothing. Read the movement InputAction.

What changed

Change Use now
ContextActionService:BindAction and related binds "planned for deprecation" Input Action System: InputContext > InputAction > InputBinding instances (key, pad, UIButton). Keep old CAS code, migrate on touch
InputAction:Fire() deprecated InputBinding:Fire(state) on a binding with Type = Scriptable; silently ignored if the action or its context is disabled; errors on a type mismatch
PreferredInput (KeyboardAndMouse, Gamepad, Touch, MicroGamepad) Present controls from it; InputAction.PreferredBinding gives the matching binding
InputActionLabel, Input Action Manager (Window > Input): beta Label shows the live key/icon for an action; Manager flags missing (yellow) and duplicate (red) bindings
Server Authority Simulation input through the IAS, processed in RunService:BindToSimulation() (needs Workspace.UseFixedSimulation), not a RemoteEvent stream

1. Menus and keys

  • Every clickable popup needs a key on PC: with the cursor locked centre, a mid-game vote can't be clicked. Route popups through a key players know; phones tap.
  • Bag/inventory on PC: pick a key outside the reserved list above (for example B, I), or disable the player list / backpack (StarterGui:SetCoreGuiEnabled) before taking Tab or backquote.
  • Menu blocking in the IAS: enable a higher-Priority InputContext with Sink that binds the gameplay keys while the menu is open; raw UserInputService handlers still need the gate above.

2. Testing

Built-in Studio MCP: user_keyboard_input, user_mouse_input, character_navigation and the rbx-device-simulator-lua skill (roblox-studio-mcp). Per feature: controller-only cold join; tap, hold, release and cancel (open a window, the Roblox menu, unplug the pad mid-hold: nothing fires); drag the camera across every touch button; switch touch -> gamepad -> mouse without respawning; Xbox, PlayStation and TV Remote in Controller Emulator. The simulator doesn't reproduce console system overlays or thumb reach: test those on hardware.