Fixed bug 3703 - Missing media keys support on Amazon Fire TV remote control
authorSam Lantinga <slouken@libsdl.org>
Thu, 20 Jul 2017 10:46:38 -0700
changeset 11149504c67e71589
parent 11148 9bdb766ec7e5
child 11150 2ee7d2fa299b
Fixed bug 3703 - Missing media keys support on Amazon Fire TV remote control

Holger Schemel

Summary: This patch adds support for key events for the "rewind" and "fast forward" media keys on the Amazon Fire TV remote control.

How to reproduce the problem: Run Android build of SDL2 application on the Amazon Fire TV (tested with "stick" version) and log key events.

Expected behaviour: Every key pressed on the Fire TV remote control should result in a corresponding key event (pressed/released).

Observed behaviour: Of the bottom row of buttons on the Fire TV remote control, only the "play/pause" (middle) button generates a key event, while the "rewind" (left) and "fast forward" (right) buttons to not generate any event at all.

The attached patch adds support for these two missing buttons/keys.

Note 1: Some missing definitions were added for the already existing key codes SDL_SCANCODE_APP1 and SDL_SCANCODE_APP2 (to keep up the correct order of enumerations / array positions when adding the two new key codes).

Note 2: Definitions in "scancodes_linux.h" and "scancodes_xfree86.h" (to also add support for these keys on other platforms) were added without testing. However, I was unable to find corresponding definitions for these two media keys for Windows and Mac OS X.

Note 3: I have also updated the (broken) link to the USB usage page standard PDF document (comment in "include/SDL_scancode.h").
include/SDL_keycode.h
include/SDL_scancode.h
src/events/SDL_keyboard.c
src/events/scancodes_linux.h
src/events/scancodes_xfree86.h
src/video/android/SDL_androidkeyboard.c
     1.1 --- a/include/SDL_keycode.h	Thu Jul 20 10:39:47 2017 -0700
     1.2 +++ b/include/SDL_keycode.h	Thu Jul 20 10:46:38 2017 -0700
     1.3 @@ -308,7 +308,12 @@
     1.4      SDLK_KBDILLUMDOWN = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KBDILLUMDOWN),
     1.5      SDLK_KBDILLUMUP = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KBDILLUMUP),
     1.6      SDLK_EJECT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_EJECT),
     1.7 -    SDLK_SLEEP = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_SLEEP)
     1.8 +    SDLK_SLEEP = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_SLEEP),
     1.9 +    SDLK_APP1 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_APP1),
    1.10 +    SDLK_APP2 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_APP2),
    1.11 +
    1.12 +    SDLK_AUDIOREWIND = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AUDIOREWIND),
    1.13 +    SDLK_AUDIOFASTFORWARD = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AUDIOFASTFORWARD)
    1.14  };
    1.15  
    1.16  /**
     2.1 --- a/include/SDL_scancode.h	Thu Jul 20 10:39:47 2017 -0700
     2.2 +++ b/include/SDL_scancode.h	Thu Jul 20 10:46:38 2017 -0700
     2.3 @@ -38,7 +38,7 @@
     2.4   *  SDL_Event structure.
     2.5   *
     2.6   *  The values in this enumeration are based on the USB usage page standard:
     2.7 - *  http://www.usb.org/developers/devclass_docs/Hut1_12v2.pdf
     2.8 + *  http://www.usb.org/developers/hidpage/Hut1_12v2.pdf
     2.9   */
    2.10  typedef enum
    2.11  {
    2.12 @@ -390,6 +390,18 @@
    2.13  
    2.14      /* @} *//* Walther keys */
    2.15  
    2.16 +    /**
    2.17 +     *  \name Usage page 0x0C (additional media keys)
    2.18 +     *
    2.19 +     *  These values are mapped from usage page 0x0C (USB consumer page).
    2.20 +     */
    2.21 +    /* @{ */
    2.22 +
    2.23 +    SDL_SCANCODE_AUDIOREWIND = 285,
    2.24 +    SDL_SCANCODE_AUDIOFASTFORWARD = 286,
    2.25 +
    2.26 +    /* @} *//* Usage page 0x0C (additional media keys) */
    2.27 +
    2.28      /* Add any other keys here. */
    2.29  
    2.30      SDL_NUM_SCANCODES = 512 /**< not a key, just marks the number of scancodes
     3.1 --- a/src/events/SDL_keyboard.c	Thu Jul 20 10:39:47 2017 -0700
     3.2 +++ b/src/events/SDL_keyboard.c	Thu Jul 20 10:46:38 2017 -0700
     3.3 @@ -273,6 +273,10 @@
     3.4      SDLK_KBDILLUMUP,
     3.5      SDLK_EJECT,
     3.6      SDLK_SLEEP,
     3.7 +    SDLK_APP1,
     3.8 +    SDLK_APP2,
     3.9 +    SDLK_AUDIOREWIND,
    3.10 +    SDLK_AUDIOFASTFORWARD,
    3.11  };
    3.12  
    3.13  static const char *SDL_scancode_names[SDL_NUM_SCANCODES] = {
    3.14 @@ -505,6 +509,10 @@
    3.15      "KBDIllumUp",
    3.16      "Eject",
    3.17      "Sleep",
    3.18 +    "App1",
    3.19 +    "App2",
    3.20 +    "AudioRewind",
    3.21 +    "AudioFastForward",
    3.22  };
    3.23  
    3.24  /* Taken from SDL_iconv() */
     4.1 --- a/src/events/scancodes_linux.h	Thu Jul 20 10:39:47 2017 -0700
     4.2 +++ b/src/events/scancodes_linux.h	Thu Jul 20 10:46:38 2017 -0700
     4.3 @@ -194,7 +194,7 @@
     4.4      /*  165 */    SDL_SCANCODE_AUDIOPREV, /* KEY_PREVIOUSSONG */
     4.5      /*  166 */    SDL_SCANCODE_AUDIOSTOP, /* KEY_STOPCD */
     4.6      /*  167 */    SDL_SCANCODE_UNKNOWN, /* KEY_RECORD */
     4.7 -    /*  168 */    SDL_SCANCODE_UNKNOWN, /* KEY_REWIND */
     4.8 +    /*  168 */    SDL_SCANCODE_AUDIOREWIND, /* KEY_REWIND */
     4.9      /*  169 */    SDL_SCANCODE_UNKNOWN, /* KEY_PHONE */
    4.10      /*  170 */    SDL_SCANCODE_UNKNOWN, /* KEY_ISO */
    4.11      /*  171 */    SDL_SCANCODE_UNKNOWN, /* KEY_CONFIG */
    4.12 @@ -230,7 +230,7 @@
    4.13      /*  205 */    SDL_SCANCODE_UNKNOWN, /* KEY_SUSPEND */
    4.14      /*  206 */    SDL_SCANCODE_UNKNOWN, /* KEY_CLOSE */
    4.15      /*  207 */    SDL_SCANCODE_UNKNOWN, /* KEY_PLAY */
    4.16 -    /*  208 */    SDL_SCANCODE_UNKNOWN, /* KEY_FASTFORWARD */
    4.17 +    /*  208 */    SDL_SCANCODE_AUDIOFASTFORWARD, /* KEY_FASTFORWARD */
    4.18      /*  209 */    SDL_SCANCODE_UNKNOWN, /* KEY_BASSBOOST */
    4.19      /*  210 */    SDL_SCANCODE_UNKNOWN, /* KEY_PRINT */
    4.20      /*  211 */    SDL_SCANCODE_UNKNOWN, /* KEY_HP */
     5.1 --- a/src/events/scancodes_xfree86.h	Thu Jul 20 10:39:47 2017 -0700
     5.2 +++ b/src/events/scancodes_xfree86.h	Thu Jul 20 10:46:38 2017 -0700
     5.3 @@ -345,7 +345,7 @@
     5.4      /* 165 */   SDL_SCANCODE_AUDIOPREV,
     5.5      /* 166 */   SDL_SCANCODE_AUDIOSTOP,
     5.6      /* 167 */   SDL_SCANCODE_UNKNOWN,   /* XF86AudioRecord */
     5.7 -    /* 168 */   SDL_SCANCODE_UNKNOWN,   /* XF86AudioRewind */
     5.8 +    /* 168 */   SDL_SCANCODE_AUDIOREWIND,   /* XF86AudioRewind */
     5.9      /* 169 */   SDL_SCANCODE_UNKNOWN,   /* XF86Phone */
    5.10      /* 170 */   SDL_SCANCODE_UNKNOWN,
    5.11      /* 171 */   SDL_SCANCODE_F13,       /* XF86Tools */
     6.1 --- a/src/video/android/SDL_androidkeyboard.c	Thu Jul 20 10:39:47 2017 -0700
     6.2 +++ b/src/video/android/SDL_androidkeyboard.c	Thu Jul 20 10:46:38 2017 -0700
     6.3 @@ -129,8 +129,8 @@
     6.4      SDL_SCANCODE_AUDIOSTOP, /* AKEYCODE_MEDIA_STOP */
     6.5      SDL_SCANCODE_AUDIONEXT, /* AKEYCODE_MEDIA_NEXT */
     6.6      SDL_SCANCODE_AUDIOPREV, /* AKEYCODE_MEDIA_PREVIOUS */
     6.7 -    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_MEDIA_REWIND */
     6.8 -    SDL_SCANCODE_UNKNOWN, /* AKEYCODE_MEDIA_FAST_FORWARD */
     6.9 +    SDL_SCANCODE_AUDIOREWIND, /* AKEYCODE_MEDIA_REWIND */
    6.10 +    SDL_SCANCODE_AUDIOFASTFORWARD, /* AKEYCODE_MEDIA_FAST_FORWARD */
    6.11      SDL_SCANCODE_MUTE, /* AKEYCODE_MUTE */
    6.12      SDL_SCANCODE_PAGEUP, /* AKEYCODE_PAGE_UP */
    6.13      SDL_SCANCODE_PAGEDOWN, /* AKEYCODE_PAGE_DOWN */