4

Does Firefox provide an API for extensions to capture media key events on OS X? These are physically located on the F7/F8/F9 keys on Apple's keyboards, but they don't have keycodes, so it seems impossible to intercept a media key press event with an onkeypress event.

To clarify: I have tried multiple JS tools which detect keycodes on onkeypress events. I can say with 100% confidence that the OS X media keys do not send an onkeypress event on any popular in-browser JS implementation unless the fn key is held down at the same time, but that isn't what I'm asking about.

To my understanding, Chrome implements a separate API which allows for capturing media key press events. I am asking if Firefox provides a similar API.

Jules
  • 14,200
  • 13
  • 56
  • 101
  • Go to this page, click in the textbox and try pressing the keys, it should tell you its keycode :) http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes if thats not it i dont understand the question totally, can you please elaborate, with pictures maybe – Noitidart Sep 22 '15 at 04:21
  • @Noitidart I've tried a number of those pages before asking, and (as explained on other pages I've researched), the OS X media keys apparently don't actually send an `onkeypress` event of any kind; they don't have a key/char code. – Jules Sep 22 '15 at 12:55
  • Can you show me what keys to push with an image im sure i can find a solution. And try keydown/keyup for some keys keycode doesnt go to keypress but does to keyup. – Noitidart Sep 22 '15 at 15:06
  • @Noitidart [Here's](http://imgur.com/vOZKCE3) an image showing the location of the keys. The act as normal function keys when holding down the `fn` button and send out key codes then, but when `fn` is being held down, they don't control media. – Jules Sep 22 '15 at 15:08
  • This works for me: `window.addEventListener('keyup', function(e) { console.log('keycode pressed:', e.key, e.keyCode, e.charCode, e); },false)` it logs to console: `keycode pressed: F12 123 0 keyup { target: , key: "F12", charCode: 0, keyCode: 123 }` – Noitidart Sep 22 '15 at 15:14
  • @Noitidart and this works for you when pressing the media keys on an OS X keyboard, without holding down `fn`? Because it doesn't seem to be working for me for those specific keys. – Jules Sep 22 '15 at 15:17
  • I am using a virtualbox setup and a windows keyboard. So I cant replicate it exactly. – Noitidart Sep 22 '15 at 15:34
  • Were you able to figure this out? Wherever I like it seems people are using F keys, in the documentation: https://developer.mozilla.org/en-US/Add-ons/SDK/High-Level_APIs/hotkeys – Noitidart Sep 27 '15 at 19:50
  • Haven't found a solution yet. Hotkeys don't seem like they'd solve this problem. – Jules Sep 27 '15 at 21:12
  • I think ill get a chance to get on a real mac within the next month, Ill update you on if i get a chance. – Noitidart Sep 27 '15 at 21:14

2 Answers2

1

Function keys do have keycodes. I guess you are talking about something like Fn + F7/F8/F9? You could intercept a multiple key combo for this. But this can get pretty messy.

See this and this for the gory details.

leeor
  • 17,041
  • 6
  • 34
  • 60
  • I'm actually more interested in capturing the media keypress events without holding down `Fn`, that's the part that doesn't seem possible in FF (at least, on OS X. Windows FF allows you to, and so does Chrome on OS X, apparently). – Jules Sep 21 '15 at 16:06
0

This addon here says it supports osx media keys: https://github.com/mikedeboer/soundcloud-player

Quote:

You might find this topic interesting: https://github.com/mstange/mediakeysappleremotesimfy/issues/1

I posted there some objective c to get keycode of the keys pressed. So you can either:

  1. Land solution right now, by using that js-ctypes, put it into a chromeworker, and have it send message to your mainthread on every time it detects a media key.
  2. Wait for webextensions api to land the media command support
Noitidart
  • 35,443
  • 37
  • 154
  • 323