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
Step 1 of 11
One 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?
Press 1 to 4 to choose, Enter to check.
Step 2 of 11
One 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?
Press 1 to 4 to choose, Enter to check.
Step 3 of 11
Aim 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?
Press 1 to 4 to choose, Enter to check.
Step 4 of 11
The 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)
Press 1 to 4 to choose, Enter to check.
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.
Step 5 of 11
Let 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.
A player rebinds WrenchSwing to Q and your menu allows it without a check. What breaks in Beacon Yard?
Press 1 to 4 to choose, Enter to check.
Step 6 of 11
Menus 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?
Press 1 to 7 to choose, Enter to check.
Step 7 of 11
Settings 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?
Press 1 to 4 to choose, Enter to check.
Step 8 of 11
Where 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?
Press 1 to 4 to choose, Enter to check.
Step 9 of 11
Build 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.
Step 10 of 11
Challenges
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
Meet the criteria above, then record your own result. No test grades this check.
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
Meet the criteria above, then record your own result. No test grades this check.
A tablet player connects and starts using a Bluetooth gamepad. Which property tells your UI to show gamepad button prompts?
Press 1 to 4 to choose, Enter to check.
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
Step 11 of 11
Recap
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