Lesson 12 of 12
Input everywhere, part 1: keyboard, gamepad, touch and accessibility
Make a Roblox game work on keyboard, gamepad and touch. Bind Beacon Yard's wrench swing everywhere, meet the Input Action System, add input remapping, gamepad UI selection, and accessibility for text size, colour and reduced motion.
By the end you can
- Bind one action to keyboard, gamepad and touch, and pick an aim path from the player's input device
- Say what the Input Action System's contexts, actions and bindings are, and let players remap a binding safely
- Make menus work with gamepad selection
- Respect players' text size, transparency and reduced-motion settings, and never signal with colour alone
Before this: The wrench: tools, raycasts, tags, Animation: the Animation Editor, Moon Animator, Animator
1One swing, three devices
Open Studio's device emulator and pick a phone. A round Swing button appears on the right of the screen. Tap it and the wrench swings, exactly as F does on a keyboard and the right trigger does on a gamepad. The majority of Roblox sessions are played on phones and tablets1, so this button is not an extra.
The emulated phone shows the WrenchSwing touch button; a tap fires the same remote as F.
Transcript
- 0:10 The phone emulator shows the WrenchSwing touch button.
- 0:13 The title is Swing.
- 0:15 The tap fires the same Swing remote as the F key.
A phone player taps Swing, a PC player presses F. What reaches the server?
Answer
The same Swing remote with an origin and a direction, from both. Every device ends in fireSwing, which fires Swing with two vectors. The server never needs to know which device was used.
Open this step in lesson mode · Link to this step · This confused me
2One action, many inputs
CombatClient binds a named action, WrenchSwing, with ContextActionService:BindAction. The third argument, true, asks Roblox to draw a touch button; the rest are the keys that trigger it2.
ContextActionService:BindAction(
"WrenchSwing",
function(_name: string, state: Enum.UserInputState, _input: InputObject)
if state ~= Enum.UserInputState.Begin then
return Enum.ContextActionResult.Pass
end
fireSwing()
return Enum.ContextActionResult.Sink
end,
true,
Enum.KeyCode.F,
Enum.KeyCode.ButtonR2
)
ContextActionService:SetTitle("WrenchSwing", "Swing")
The handler only acts on UserInputState.Begin, so one press is one swing, and returns Sink so the press does not also fall through to other bindings. The Tool.Activated event is a third door into the same fireSwing, for a click or tap while the tool is equipped.

Select a numbered pin, or a row below, to read what it marks.
The device emulator. Select the pins to find the Swing button and the scaled HUD.
The WrenchSwing handler returns Enum.ContextActionResult.Pass for every state except Begin. Why?
Answer
Releases and other states are not swings, so other bindings may use them. Only the press is a swing. Passing the rest keeps the binding from swallowing input it does not use.
Open this step in lesson mode · Link to this step · This confused me
3Aim depends on the device
A mouse can point anywhere on screen; a thumb on glass or a thumbstick cannot. aim picks a path with UserInputService.MouseEnabled. With a mouse, it casts a ray from the cursor. Without one, it uses the head and the camera's look direction.
if not UserInputService.MouseEnabled then
local look = unitOrNil(camera.CFrame.LookVector)
if look == nil then
return nil, nil
end
return headPos, look
It does not test TouchEnabled. Touch-screen laptops report TouchEnabled and still have a mouse, so "has touch" does not mean "is a phone"3. For UI that should change with the device the player is using right now, read UserInputService.PreferredInput, which follows the player's most recent input.
A player on a touch-screen laptop swings with the mouse. Which aim path does Beacon Yard use?
Answer
The mouse ray, because MouseEnabled is true. aim branches on MouseEnabled. A laptop with a mouse aims with the cursor even though it also has a touch screen.
Open this step in lesson mode · Link to this step · This confused me
4The newer way: the Input Action System
The ContextActionService reference now says BindAction is not recommended for new work and is planned for deprecation2. Its replacement is the Input Action System: instead of calling a function, you create instances4.
- An
InputContextgroups actions, such asPlayContextfor gameplay andMenuContextfor an open menu.Enabledswitches the whole group.Prioritydecides which context hears a key first, andSinkstops that key from reaching contexts below it. - An
InputActionis one thing the player does, such asWrenchSwing. WithTypeset toBool, it firesPressedonce per press andReleasedonce per release. - Each
InputBindingunder an action is one way to do it: aKeyCodesuch asForButtonR2, or aUIButtonthat points at aGuiButtonfor touch. The system draws no touch button for you. You make the button and link it.
Here is the swing as instances, built from code in a client script:
local play = Instance.new("InputContext")
play.Name = "PlayContext"
play.Parent = inputsFolder -- ReplicatedStorage.Inputs, as the guide recommends
local swing = Instance.new("InputAction")
swing.Name = "WrenchSwing"
swing.Type = Enum.InputActionType.Bool
swing.Parent = play
for _, key in { Enum.KeyCode.F, Enum.KeyCode.ButtonR2 } do
local binding = Instance.new("InputBinding")
binding.KeyCode = key
binding.Parent = swing
end
local touch = Instance.new("InputBinding")
touch.UIButton = swingButton -- a TextButton you placed in a ScreenGui
touch.Parent = swing
swing.Pressed:Connect(fireSwing)
Open Window > Input > Actions to edit contexts, actions and bindings in the Input Action Manager. InputActionLabel is a Studio beta. In a published game, use InputAction.PreferredBinding to get the current binding and render its key or button hint.
The m06 WrenchSwing handler checks the input state and returns Pass or Sink. Connected to swing.Pressed instead, what does it need?
swing.Pressed:Connect(fireSwing)
Answer
Nothing extra: Pressed fires once per press with no state, so fireSwing is the whole handler. Pressed and Released split the states for you, and Sink moved to the context. That is why the migration in part 2 deletes code from the handlers.
Other ways pros do this
| Option | What it is | When pros pick it | Trade-offs |
|---|---|---|---|
| Input Action System | InputContext, InputAction and InputBinding instances, set up in Studio or from code. | New games and anything with menus that should switch controls, rebinding, or on-screen prompts. | Newer, so fewer tutorials and community examples, and you build your own touch buttons. |
| ContextActionService | BindAction with a callback, keys and an optional touch button. | Existing code such as Beacon Yard's Controls.luau, which still uses it at m14-ship. | Not recommended for new work and planned for deprecation. |
| UserInputService events | InputBegan and InputEnded for every raw input. | Custom cameras, drag gestures and anything an action map cannot express. | You handle every device and every conflict yourself. |
Match each job to the tool that fits it best.
Answer
A new Dash action on keyboard, gamepad and touch, rebindable: Input Action System; Keep m06's WrenchSwing working while you migrate: ContextActionService; A pinch-to-zoom gesture on the map screen: UserInputService events. New actions belong in the Input Action System. Existing BindAction code keeps working until it is migrated. Gestures that are not simple presses use raw input events.
Open this step in lesson mode · Link to this step · This confused me
5Let players remap
Many players need a different key: left-handed players, players with one hand, players whose keyboard has no easy F. With the Input Action System, remapping is changing a property. InputBinding.KeyCode is writable at runtime, so a settings menu can listen for the next key and assign it. Save the choice in the player's profile and apply it on join.
Two rules keep remapping safe. Reserved inputs such as Esc and F9 (an example list) cannot be bound. And a new key must not silently steal one that another action uses.
local bindings = { WrenchSwing = "F", CameraFieldOfView = "Q", Interact = "E" }
local RESERVED = { Escape = true, F9 = true, F11 = true, F12 = true }
local function remap(action, key)
if RESERVED[key] then
return false, key .. " is reserved"
end
for other, used in bindings do
if other ~= action and used == key then
return false, key .. " is already " .. other
end
end
bindings[action] = key
return true, action .. " is now " .. key
end
print(remap("WrenchSwing", "Q"))
print(remap("WrenchSwing", "F9"))
print(remap("WrenchSwing", "G"))
false Q is already CameraFieldOfView
false F9 is reserved
true WrenchSwing is now GA player rebinds WrenchSwing to Q and your menu allows it without a check. What breaks in Beacon Yard?
Answer
Q is already bound to the camera, so the actions compete for the same key. CameraFieldOfView already uses Q. A remap screen must detect the clash and ask, or the player loses the zoom or gets two actions per press.
Open this step in lesson mode · Link to this step · This confused me
6Menus on a gamepad
A gamepad has no cursor. To use a menu, the player moves a selection from button to button with the stick or D-pad and presses a button to activate it. GuiService.SelectedObject is the element that currently has the selection5. GuiButtons are selectable by default; NextSelectionUp, Down, Left and Right override where the stick goes.
The m06 shop does not set a selection when it opens. A gamepad player has to press the Select button to enter UI navigation before they can buy anything. The m07 fix is three lines: when the shop opens, set GuiService.SelectedObject to the first button; when it closes, set it to nil; and let ButtonB close it.
A gamepad player opens the shop and can buy, but after closing it their thumbstick still moves an invisible selection instead of the character. Which line is missing its partner?
local function openShop()
shop.Visible = true
GuiService.SelectedObject = speedButton
end
local function closeShop()
shop.Visible = false
end
Answer
Line 6: shop.Visible = false. Fixed: shop.Visible = false GuiService.SelectedObject = nil. Opening sets the selection; closing must clear it, or navigation stays on a hidden button. Set SelectedObject to nil when the menu closes.
Open this step in lesson mode · Link to this step · This confused me
7Settings players already chose
Players set preferences in Roblox's own settings menu, and your UI can read them6:
- Text size.
GuiService.PreferredTextSizegrows text rendered at a fixedTextSize. Text withTextScaledon does not grow. Beacon Yard's HUD uses fixed sizes (22, 18, 16), so it follows the setting. - Background transparency.
GuiService.PreferredTransparencyis 1 by default and 0 for players who want solid panels. Multiply yourBackgroundTransparencyby it. - Reduce motion.
GuiService.ReducedMotionEnabledis true for players who want less movement.CameraClienttweens the field of view over 0.35 seconds when you pressQ; with reduced motion on, it should snap or fade instead. - Colour. Over 5% of people have some colour blindness. Never let colour alone carry meaning: a stunned drone turns white and gets an outline, and the shop's buttons are coloured and labelled.
Reference Player preference properties
Listen with GetPropertyChangedSignal on each, because players can change them during a session.
Enum.PreferredTextSize- Medium by default; Large, Larger or Largest when the player wants bigger text.
number, 0 to 1- 1 by default; 0 when the player wants opaque backgrounds. Multiply BackgroundTransparency by it.
boolean- True when the player wants motion reduced or removed.
GuiObject?- The element gamepad navigation has selected; set it when a menu opens, clear it when it closes.
Enum.PreferredInput- Touch, KeyboardAndMouse or Gamepad, following the player's most recent input.
Which of these respect the player's settings and needs?
Answer
TweenInfo.new(if GuiService.ReducedMotionEnabled then 0 else 0.35) for the FOV change; Labels with a fixed TextSize, so PreferredTextSize can grow them. A zero-time tween snaps for reduced-motion players, and fixed text sizes follow the text-size setting. TextScaled ignores PreferredTextSize, and colour alone fails colour-blind players; Beacon Yard adds an outline.
Open this step in lesson mode · Link to this step · This confused me
8Where the front desk picture breaks
Both sidesRemember: A RemoteEvent is a note to the front-desk clerk.
Three devices, one note to the front desk. The clerk does not care whether you wrote it with a pen, a keyboard or a thumb. Answer first, then open the breakdown.
Where does it break?“A note to the front-desk clerk” is a good picture of a remoteevent. Where does it stop being true?
It breaks here. The engine stamps the sender for you, but every other word on the note can be a lie.
The true model. A RemoteEvent carries a one-way message between a client and the server. The server always learns which player sent it; every other argument is untrusted input that the server must check.
Someone suggests letting touch players send a bigger WRENCH_RANGE in the Swing remote, because aiming on glass is harder. Why is that a bad idea?
Answer
The server cannot verify which device sent the note, so every cheater would claim to be on touch. The server knows who sent a remote, not what they used. Make touch easier on the client (aim assist, a bigger button) and keep the server's checks the same for everyone.
Open this step in lesson mode · Link to this step · This confused me
9Build it: input and accessibility for m07
Build along
src/client/Controls.luausrc/client/Accessibility.luausrc/client/CombatClient.luausrc/client/CameraClient.luausrc/client/ShopGui.luau
Press Play, open the device emulator from the Test tab and choose a phone.
You should see The emulator shows the phone layout with a Swing button; tapping it swings and the drone takes damage during a drill.
Check out
m07-feeland inspectsrc/client/Controls.luauandgit diff m06-drone-wrench m07-feel -- src/client/CombatClient.luau. Notice thatm07-feelputs every binding inControls.luau. That one file is what keeps the move to the Input Action System small, as part 2 shows.You should see Controls.luau holds one BINDINGS table for WrenchSwing, CameraFieldOfView, OpenSettings and CloseShop, and wraps ContextActionService:BindAction so CombatClient, CameraClient and ShopGui all bind through Controls.bind.
Open
src/client/Accessibility.luauandsrc/client/CameraClient.luau.Accessibility.start()seeds theReducedMotionplayer attribute fromGuiService.ReducedMotionEnabled, andCameraClientchecksAccessibility.reducedMotion()to snap instead of tweening. Toggle Reduce Motion in the Roblox settings menu or the yard's Settings panel and pressQ.You should see Pressing Q (or Y on a gamepad, or Zoom on touch) with ReducedMotion on snaps camera.FieldOfView directly instead of tweening.
Open
src/client/ShopGui.luauand find where it setsGuiService.SelectedObject = speedButton, bindsCloseShop(ButtonB) while open, and clearsSelectedObjectwhen closing.You should see Opening the shop with a gamepad highlights the Speed button at once; ButtonB closes it via CloseShop and clears GuiService.SelectedObject so the thumbstick moves the character again.
Open the yard's Settings panel (
Pon keyboard,DPadUpon gamepad, or the Settings touch button) to toggle Large text and check howAccessibility.textrescales the HUD and shop.You should see With LargeText on (or Roblox's Text Size raised), the registered HUD and shop labels scale up and still fit their panels.
Open this step in lesson mode · Link to this step · This confused me
10Challenges
Level 1, Apprentice
Challenge
Rename the touch button and find it in the emulator.
- Start from
- The game at milestone m06 (download)
Done means
- In the device emulator, the touch button reads a new title
- The title is Swing again afterwards
Hints
- SetTitle is called right after BindAction.
- Do not add a second BindAction for the wrench.
Level 2, Builder
Challenge
Make the field-of-view zoom respect Reduce Motion.
- Start from
- The game at milestone m06 (download)
Done means
- With Reduce Motion on, Q changes the field of view with no tween
- With it off, the 0.35-second tween is unchanged
- Changing the setting during Play takes effect on the next press
Hints
- Read GuiService.ReducedMotionEnabled at the moment of the press, not once at start.
- A TweenInfo with time 0 snaps.
A tablet player connects and starts using a Bluetooth gamepad. Which property tells your UI to show gamepad button prompts?
Answer
UserInputService.PreferredInput. PreferredInput reports Gamepad once a gamepad is connected and used, even on a touch device. TouchEnabled would still be true.
Level 3, Professional
Challenge
Add a YardHint action with ContextActionService without disturbing the wrench. (Use ContextActionService: the test reads it.)
- Start from
- The game at milestone m06 (download)
- Grade it
- To grade work from an earlier milestone, apply your challenge changes to a checkout based on
m14-ship, which includes the Course Runner. In Studio, press Play, then runrequire(game.ReplicatedStorage.GameTests.RunChallenge)("input-mobile", "input-yard-hint")in the client command bar. Copy the pass code from Output.
Done means
- A second action named YardHint is bound on the client with ContextActionService:BindAction
- YardHint creates a touch button (createTouchButton = true) and binds Enum.KeyCode.G and Enum.KeyCode.ButtonL2
- The WrenchSwing binding via ContextActionService is unchanged: touch button, F and ButtonR2
- challenges/input-mobile.luau, run on the client, prints TEST PASS yard_hint
Hints
- Bind YardHint in a new client module, not inside CombatClient, using ContextActionService:BindAction (the test reads ContextActionService:GetAllBoundActionInfo(), so an Input Action System binding will not be seen).
- Pass true for createTouchButton, plus Enum.KeyCode.G and Enum.KeyCode.ButtonL2.
- Run the check from the client command bar during Play.
Open this step in lesson mode · Link to this step · This confused me
11Recap
Recap
- One named action takes keyboard, gamepad and touch, and every device sends the same Swing remote; aim branches on MouseEnabled, and PreferredInput follows the current device.
- BindAction is legacy; the Input Action System's contexts, actions and bindings make remapping a property change, with reserved keys and conflicts checked.
- Menus set and clear GuiService.SelectedObject for gamepads, and UI respects text size, transparency, reduced motion and never relies on colour alone.
- Controls.luau holds every binding in one table, which is what keeps the move to the Input Action System in part 2 small.
A RemoteEvent is a note to the front-desk clerk, until the engine stamps the sender for you, but every other word on the note can be a lie.
Queued for review
- A player on a touch-screen laptop swings with the mouse. Which aim path does Beacon Yard use?
- A player rebinds WrenchSwing to Q and your menu allows it without a check. What breaks in Beacon Yard?
- Which of these respect the player's settings and needs?
- A tablet player connects and starts using a Bluetooth gamepad. Which property tells your UI to show gamepad button prompts?
Next Input everywhere, part 2: move the yard to the Input Action System
Open this step in lesson mode · Link to this step · This confused me