SuperAPI AI 工具集

roblox-input

编程与开发

查看项目

更新于 10-16 09:41

技能介绍

Roblox Input

何时加载

处理触摸、手柄、键盘、鼠标或体感输入、屏幕动作按钮、跨平台绑定时使用。仅限客户端;服务器权威模拟输入使用 Input Action System。

快速参考

事件:InputBegan/Changed/Ended 提供 (input, gameProcessedEvent);用于游戏玩法时需对其进行过滤。Wheel 只触发 InputChanged。

绑定:优先使用 ContextActionService:BindAction(name, handler, touchButton, ...keys);按状态做门控(触摸为 KeyCode.Unknown);注意堆叠顺序,因此使用 BindActionAtPriority。服务器权威:InputAction/InputContext + RunService:BindToSimulation()(需要 Workspace.UseFixedSimulation)。

移动端优先、兼顾混合输入:根据 UserInputService.PreferredInput(Enum.PreferredInput)显示控件,并通过 GetPropertyChangedSignal 观察变化,而不是一次性缓存 TouchEnabled。

触摸动作按钮:只有从按钮上开始的触摸才会触发;摄像机拖拽经过按钮时永远不会触发。放置位置参考 PlayerGui.TouchGui 下测量得到的跳跃按钮;清空拇指摇杆区域。

玩法门控:当游戏窗口打开、TextBox 聚焦、GuiService.MenuIsOpen,或 GuiService.SelectedObject 已设置时阻止攻击。

取消不是释放:窗口打开、Cancel、卸下装备、失去焦点、输入切换或手柄断开时保持取消状态。

手柄工具:默认控制通过 BindActivate 绑定 ButtonR2;Tool.ManualActivationOnly = true 会禁用它。手柄上瞄准应取屏幕中心,而不是 GetMouseLocation()。

提示:GetStringForKeyCode(key, Enum.KeyCodeStringFormat.Abbreviated)、GetImageForKeyCode 或 InputActionLabel;不要硬编码 Xbox 名称。

测试:Device Simulator + Controller Emulator;菜单焦点在 roblox-gui 中。

详细信息:references/full.md