Is there a way to access the “media keys” with Javascript from within a browser tab/window?
I am mainly interested in a google chrome solution.
Using the following code, there doesn’t seem to be an event generated for the media keys:
<html>
<body onKeyDown="showKeyCode(event)">
<script type="text/javascript">
function showKeyCode(event) {
alert(event.keyCode);
}
</script>
</body>
</html>
Am I missing something? Could I do better with a Google Chrome extension??
Update: to address this problem I crafted the following tools:
- Chrome MusicMan
- Mediakeys Server
Edit: There is now explicit support for media keys. The answer below is deprecated. See @thakis answer below.
Old 2012 answer
Regarding whether you could do better than a Chrome Extension: no you could not – I’ve made a content script for a site, and running it within the current stable release of Chrome 16 on OS X 10.7. The script is simple enough:
And it shows that no events are triggered for the back, play/pause, forward, mute, volume down or volume up keys.
Interesting the unused F5 key goes generate a keycode, so you could potentially use it as an alternative if you wish.