--- orphan: true --- # Standard Controls move, jump, shoot at the cursor, and rebind any of it. ```{raw} html ▶ Run in browser ``` **Tags:** `input` `actions` `rebinding` `keyboard` `mouse` `controller` `touch` The controls nearly every game has, written the way SimVX spells them: a movement action on WASD or the left stick, jump on Space or pad A, shoot on a left click (at the cursor) or pad X, and a rebind screen with two tables: the pad's controls (which physical button ``Controller.A`` is) and the actions (which names ``jump`` answers to). Each cell listens for the next control the player presses and binds that; its listener claims the press, so choosing Space for jump does not also jump. ## What it demonstrates - Actions in ``input_context`` typed by their bindings: ``Axis2D.WASD`` and ``Controller.LEFT_STICK`` make ``move`` a ``Vec2``, buttons make ``jump`` and ``shoot`` a bool. - ``@on_input("jump")`` fires once per press; a handler hears a release only when it asks with ``edge="release"``. - ``InputListener``: a cell adds one and binds what it hears in one line, ``InputMap.rebind(target, heard)``. Cancelling is the cell's own choice (Esc, or whatever the player has made pad Back). - **Two tables, one map.** A device row rebinds an engine entry, ``InputMap.rebind(Controller.A, heard)``, and every action using ``Controller.A`` follows; ``InputMap.swap`` turns a pad with A and B the wrong way round. An action row binds the press by the engine entry the map has for it, so it follows the device table, a chord with what was held for it, and the raw control when the player has left nothing naming it. - **Mapping an unrecognised controller.** A flight stick no controller database knows has only numbered controls. "Map a controller" walks the standard names in turn with the same one line; a press on an unrecognised controller maps the name on that device alone, so the game's actions, which name ``Controller.A``, play on it, and the mapping is saved with the rest of the player's rebinds, filed under the device. - ``Input.label`` printing a control, raw or named, the way the hardware counts or names it. - ``InputContext(hides=InputContext.ALL)`` on the rebind screen, so the game stands still while it is open. - "Reset to defaults" calls ``InputMap.clear_rebinds()``: the player's changes are one override layer over the bindings the game declared, so dropping it is the whole of a reset, device mappings included. Controls: WASD / left stick / drawn stick - Move SPACE / pad A - Jump Left click / pad X - Shoot at the cursor TAB / pad Start / Controls - Open the rebind screen (Esc, Tab or Start closes it) ESC / pad Back - Cancel a rebind, or close the screen Run: simvx examples run features_input_standard_controls Headless self-check: simvx examples run features_input_standard_controls --test ## Source ```{literalinclude} ../../examples/features/input/standard_controls.py :language: python :linenos: ```