> For the complete documentation index, see [llms.txt](https://docs.mapbox.com/mapbox-gl-js/llms.txt)

# Navigate the map with game-like controls

In this example, the user can press their keyboard's arrow keys to move around the map with game-like controls.

The map uses [`panBy`](https://docs.mapbox.com/mapbox-gl-js/api/map/#map#panby) to move forward and backward, and [`easeTo`](https://docs.mapbox.com/mapbox-gl-js/api/map/#map#easeto) to move left and right.

> Example code:

**JavaScript**

```html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Navigate the map with game-like controls</title>
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
<link href="https://api.mapbox.com/mapbox-gl-js/v3.28.1/mapbox-gl.css" rel="stylesheet">
<script src="https://api.mapbox.com/mapbox-gl-js/v3.28.1/mapbox-gl.js"></script>
<style>
body { margin: 0; padding: 0; }
#map { position: absolute; top: 0; bottom: 0; width: 100%; }
</style>
</head>
<body>
<div id="map"></div>

<script>
    const map = new mapboxgl.Map({
        // TO MAKE THE MAP APPEAR YOU MUST
        // ADD YOUR ACCESS TOKEN FROM
        // https://account.mapbox.com
        accessToken: 'YOUR_MAPBOX_ACCESS_TOKEN',
        container: 'map',
        // Choose from Mapbox's core styles, or make your own style with Mapbox Studio
        style: 'mapbox://styles/mapbox/standard',
        config: {
            basemap: {
                theme: 'monochrome',
                lightPreset: 'night'
            }
        },
        center: [-87.6298, 41.8781],
        zoom: 17,
        bearing: -12,
        pitch: 60,
        boxZoom: false,
        doubleClickZoom: false,
        dragPan: false,
        dragRotate: false,
        keyboard: false,
        scrollZoom: false,
        touchPitch: false,
        touchZoomRotate: false
    });

    // pixels the map pans when the up or down arrow is clicked
    const deltaDistance = 100;

    // degrees the map rotates when the left or right arrow is clicked
    const deltaDegrees = 25;

    function easing(t) {
        return t * (2 - t);
    }

    map.on('load', () => {
        map.getCanvas().focus();
        map.getCanvas().parentNode.classList.remove('mapboxgl-interactive');

        map.getCanvas().addEventListener(
            'keydown',
            (e) => {
                e.preventDefault();
                if (e.which === 38) {
                    // up
                    map.panBy([0, -deltaDistance], {
                        easing: easing
                    });
                } else if (e.which === 40) {
                    // down
                    map.panBy([0, deltaDistance], {
                        easing: easing
                    });
                } else if (e.which === 37) {
                    // left
                    map.easeTo({
                        bearing: map.getBearing() - deltaDegrees,
                        easing: easing
                    });
                } else if (e.which === 39) {
                    // right
                    map.easeTo({
                        bearing: map.getBearing() + deltaDegrees,
                        easing: easing
                    });
                }
            },
            true
        );
    });
</script>

</body>
</html>
```

**React**

```jsx
import React, { useEffect, useRef } from 'react';
import * as mapboxgl from 'mapbox-gl/esm';

import 'mapbox-gl/dist/mapbox-gl.css';

const MapboxExample = () => {
  const mapContainerRef = useRef();
  const mapRef = useRef();

  useEffect(() => {
    mapRef.current = new mapboxgl.Map({
      // TO MAKE THE MAP APPEAR YOU MUST
      // ADD YOUR ACCESS TOKEN FROM
      // https://account.mapbox.com
      accessToken: 'YOUR_MAPBOX_ACCESS_TOKEN',
      container: mapContainerRef.current,
      style: 'mapbox://styles/mapbox/standard',
      config: {
        basemap: {
          theme: 'monochrome',
          lightPreset: 'night'
        }
      },
      center: [-87.6298, 41.8781],
      zoom: 17,
      bearing: -12,
      pitch: 60,
      boxZoom: false,
      doubleClickZoom: false,
      dragPan: false,
      dragRotate: false,
      keyboard: false,
      scrollZoom: false,
      touchPitch: false,
      touchZoomRotate: false
    });

    const deltaDistance = 100;
    const deltaDegrees = 25;

    function easing(t) {
      return t * (2 - t);
    }

    mapRef.current.on('load', () => {
      mapRef.current.getCanvas().focus();
      mapRef.current
        .getCanvas()
        .parentNode.classList.remove('mapboxgl-interactive');

      mapRef.current.getCanvas().addEventListener(
        'keydown',
        (e) => {
          e.preventDefault();
          if (e.which === 38) {
            mapRef.current.panBy([0, -deltaDistance], {
              easing: easing
            });
          } else if (e.which === 40) {
            mapRef.current.panBy([0, deltaDistance], {
              easing: easing
            });
          } else if (e.which === 37) {
            mapRef.current.easeTo({
              bearing: mapRef.current.getBearing() - deltaDegrees,
              easing: easing
            });
          } else if (e.which === 39) {
            mapRef.current.easeTo({
              bearing: mapRef.current.getBearing() + deltaDegrees,
              easing: easing
            });
          }
        },
        true
      );
    });
  }, []);

  return <div id="map" ref={mapContainerRef} style={{ height: '100%' }}></div>;
};

export default MapboxExample;
```