luke-chang / js-spatial-navigation

A javascript-based implementation of Spatial Navigation.
Mozilla Public License 2.0
370 stars 117 forks source link

Add support to provide configurable key mappings #63

Closed Boubalou closed 6 months ago

Boubalou commented 6 months ago

📖 Description

Change the hardcoded key mapping and select key to the global configuration, allowing integrator to provide their own sets of custom key mapping.

This is mandatory to work on Xbox one with the game controller, for instance.

Example of the key mapping to provide to support Xbox one:

var selectKeyCodes = [13, 195];

var keyMapping = {
  '37': 'left',
  '205': 'left',
  '38': 'up',
  '203': 'up',
  '39': 'right',
  '206': 'right',
  '40': 'down',
  '204': 'down'
};

SpatialNavigation.set({keyMapping, selectKeyCodes})