> For the complete documentation index, see [llms.txt](https://wiki.playgama.com/playgama/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://wiki.playgama.com/playgama/guides/game-development/controls.md).

# Controls and input

Keyboard, mouse and touch controls that work on every device, and input during pauses and ads.

Every game is playable on desktop, and on mobile too when mobile devices are declared. Broken or missing controls on one of them is one of the most common reasons a game is sent back. The rules are in sections 1.4 and 1.5 of the [Technical Requirements](/playgama/game-requirements/technical-requirements.md).

## Support both input types from the start

* Route input through one layer that turns raw events into game actions — "jump", "move left", "select tile" — and bind both keyboard/mouse and touch to those actions. Adding touch at the end of development usually breaks something.
* In plain JS, use Pointer Events (`pointerdown`, `pointermove`, `pointerup`): one code path covers mouse, touch and pen.
* Pick the scheme by device, not by screen size: use [`device.type`](/playgama/bridge-sdk/api/device.md#device-type) — tablets get the touch controls.
* If both mobile and desktop are supported, test both schemes on every build (item 1.5.3).

## Keyboard

* Show which keys do what: a short hint on the first screen or in the pause menu.
* Support both WASD and the arrow keys for movement. Read physical key positions (`KeyboardEvent.code`, such as `KeyW`), not characters (`event.key`), so the controls also work on AZERTY and other layouts.
* Never use Esc (item 1.5.2) — the browser reserves it for leaving full screen. Use P or a pause button instead.
* Do not bind browser and system shortcuts such as Ctrl/Cmd+W, Ctrl/Cmd+R, F5 or F11.
* Call `preventDefault()` on the arrow keys, Space and the mouse wheel while the game has focus, so the page around the game does not scroll.
* The game usually runs inside an iframe: make sure it takes keyboard focus after the first click or tap, and does not lose its pressed keys when focus moves away and back.

## Mouse

* Buttons react to a click, not to hover only — hover does not exist on touch devices.
* If the game captures the pointer for camera control, release it on pause, in menus and when an ad opens.

## Touch

* Touch controls respond on the first tap, without delay and without double-tap zoom: set `touch-action: none` on the game canvas.
* Long presses do not select text, open the context menu or show the iOS magnifier (item 1.4.5) — see [Responsive layout](/playgama/guides/game-development/responsive-layout.md#page-setup-for-plain-html5-games) for the CSS.
* Make on-screen buttons and joysticks big enough for a thumb (at least about 44×44 CSS pixels), keep them away from the screen edges and the [`device.safeArea`](/playgama/bridge-sdk/api/device.md#safe-area) insets, and keep the main actions reachable with one hand (item 1.6.6).
* Support multi-touch where the game needs two inputs at once, such as a joystick and a jump button.
* Text input fields open the on-screen keyboard when tapped (item 1.4.2).

## Pause and resume

* Give the player a pause button and a way home to the main menu on every gameplay screen, with the mute button next to them (see [Sound](/playgama/guides/game-development/sound.md)).
* Stop reading input while the game is paused by the platform ([`PAUSE_STATE_CHANGED`](/playgama/bridge-sdk/api/platform.md#pause)) or while a full-screen ad is open ([interstitial state](/playgama/bridge-sdk/api/advertisement/interstitial.md#interstitial-state)), and clear held keys and touches when it resumes, so the character does not keep running.
