Search code examples
javascriptjquerykeyboardkeyboard-events

Detect press of "next track" button on keyboard?


I would like to be able to detect when the "next track," "previous track," and (where applicable) "shuffle" buttons on the user's keyboard. Is this even possible? Thanks!


Solution

  • if you know the key code you can. Although not all keyboards will have it, or perhaps will differ. (guessing)

    see the keycode by doing this and hitting a key:

    $(window).keydown( function(event){ console.log(event.keyCode); } );
    

    when you have the code you can handle the event when that key is hit.

    Fiddle: http://jsfiddle.net/JyKMN/