Binding Key Events

This allows you to configure certain events to trigger on key presses. The main piece of information needed is the key code (http://keycode.info/)[http://keycode.info/]. Once you have that, you can make an object that references a certain event key. There are 6 events that you can bind a key code to:

  • prev (on key down, goes to previous song)
  • next (on key down, goes to next song)
  • play_pause (on key down, toggles play/pause)
  • stop (on key down, stops the song)
  • shuffle (on key down, toggles shuffle state global)
  • repeat (on key down, toggles repeat state global)

To add a binding, for example, the right arrow key on a mac keyboard has code 39 you'd add the following to your config:

	Amplitude.init({
		"bindings": {
			39: 'next'
		},
		"songs": [{}]
	})

Now every time the right arrow down is pressed, AmplitudeJS will go to the next song. You can add multiple bindings to the array with multiple key codes. It could be any key you want!