function bindGamepad(index, button, keyCode) {
	// Throw an exception if no action is defined for the specified keycode
	if (!getBindingKey(keyCode)) {
		throw new Error("no action defined for keycode " + keyCode);
	}

	// register to the the update event if not yet done and supported by the browser
	// if not supported, the function will fail silently (-> update loop won't be called)
	if (
		!eventEmitter.hasListener(GAME_BEFORE_UPDATE, updateGamepads) &&
		typeof navigator.getGamepads === "function"
	) {
		eventEmitter.addListener(GAME_BEFORE_UPDATE, updateGamepads);
	}

	// Allocate bindings if not defined
	if (!bindings[index]) {
		bindings[index] = {
			axes: {},
			buttons: {},
		};
	}

	const mapping = {
		keyCode: keyCode,
		value: 0,
		pressed: false,
		threshold: button.threshold, // can be undefined
	};
	const binding = bindings[index][button.type];

	// Map the gamepad button or axis to the keycode
	if (button.type === "buttons") {
		// buttons are defined by a `gamePadButton` object
		binding[button.code] = mapping;
	} else if (button.type === "axes") {
		// normalize threshold into a value that can represent both side of the axis
		const range = Math.sign(button.threshold) || 1;
		// axes are defined using two objects; one for negative and one for positive
		if (!binding[button.code]) {
			binding[button.code] = {};
		}
		const axes = binding[button.code];
		axes[range] = mapping;

		// Ensure the opposite axis exists
		if (!axes[-range]) {
			axes[-range] = {
				keyCode: 0,
				value: 0,
				pressed: false,
				threshold: -range,
			};
		}
	}
}
Associate a gamepad event to a keycode
@param {number} index - Gamepad index
@param {object} button - Button/Axis definition
@param {string} button.type - "buttons" or "axes"
@param {number} button.code - button or axis code id (See {@link input.GAMEPAD})
@param {number} [button.threshold=1] - value indicating when the axis should trigger the keycode (e.g. -0.5 or 0.5)
@param {number} keyCode - (See {@link input.KEY})
@example
// enable the keyboard
me.input.bindKey(me.input.KEY.X, "shoot");
...
// map the lower face button on the first gamepad to the X key
me.input.bindGamepad(0, {type:"buttons", code: me.input.GAMEPAD.BUTTONS.FACE_1}, me.input.KEY.X);
// map the left axis value on the first gamepad to the LEFT key
me.input.bindGamepad(0, {type:"axes", code: me.input.GAMEPAD.AXES.LX, threshold: -0.5}, me.input.KEY.LEFT);