scrcpy icon indicating copy to clipboard operation
scrcpy copied to clipboard

Media control Shortcuts

Open MonDV opened this issue 4 years ago • 9 comments

I have been using vysor to control my FireTV devices and since they upgraded to v3 it's been a complete cluster****. Found your tool yesterday and it does 99% of everything I need and it is GREAT!

There is one issue/request. Can you add media control shortcuts? Specifically to rewind, play/pause, forward media. For the FireTV the keycodes are:

KEYCODE_MEDIA_PLAY_PAUSE KEYCODE_MEDIA_REWIND KEYCODE_MEDIA_FAST_FORWARD

In vysor, I modify the settings so that my current laptop buttons for these 'functions' is linked to the keycode (currently F9, F10 and F11 buttons).

It would be great to add shortcuts that would pass those keycodes so that it is possible to control media play through scrcpy.

FYI, I am not a programmer and I don't know the complexity of this request. Best, MonDV (Thanks for the great tool!!!)

MonDV avatar Oct 10 '20 15:10 MonDV

Just to test, this works:

diff --git a/app/src/event_converter.c b/app/src/event_converter.c
index ab48898d..dc88c239 100644
--- a/app/src/event_converter.c
+++ b/app/src/event_converter.c
@@ -96,6 +96,9 @@ convert_keycode(SDL_Keycode from, enum android_keycode *to, uint16_t mod,
         MAP(SDLK_RCTRL,        AKEYCODE_CTRL_RIGHT);
         MAP(SDLK_LSHIFT,       AKEYCODE_SHIFT_LEFT);
         MAP(SDLK_RSHIFT,       AKEYCODE_SHIFT_RIGHT);
+        MAP(SDLK_F9,           AKEYCODE_MEDIA_PLAY_PAUSE);
+        MAP(SDLK_F10,          AKEYCODE_MEDIA_REWIND);
+        MAP(SDLK_F11,          AKEYCODE_MEDIA_FAST_FORWARD);
     }
 
     if (!(mod & (KMOD_NUM | KMOD_SHIFT))) {

But there is no customizable mapping on scrcpy (and media keys are not correctly received by SDL, for example I never receive SDLK_AUDIOPLAY if I click on my mediakey PLAY).

rom1v avatar Nov 09 '20 20:11 rom1v

Just to test, this works:

diff --git a/app/src/event_converter.c b/app/src/event_converter.c
index ab48898d..dc88c239 100644
--- a/app/src/event_converter.c
+++ b/app/src/event_converter.c
@@ -96,6 +96,9 @@ convert_keycode(SDL_Keycode from, enum android_keycode *to, uint16_t mod,
         MAP(SDLK_RCTRL,        AKEYCODE_CTRL_RIGHT);
         MAP(SDLK_LSHIFT,       AKEYCODE_SHIFT_LEFT);
         MAP(SDLK_RSHIFT,       AKEYCODE_SHIFT_RIGHT);
+        MAP(SDLK_F9,           AKEYCODE_MEDIA_PLAY_PAUSE);
+        MAP(SDLK_F10,          AKEYCODE_MEDIA_REWIND);
+        MAP(SDLK_F11,          AKEYCODE_MEDIA_FAST_FORWARD);
     }
 
     if (!(mod & (KMOD_NUM | KMOD_SHIFT))) {

But there is no customizable mapping on scrcpy (and media keys are not correctly received by SDL, for example I never receive SDLK_AUDIOPLAY if I click on my mediakey PLAY).

How to use this ? click on F9, F10 and f11 ? Doesn't seems to works for me. But I'm on MI9T's Android 10 MIUI, is it the reason why it doesn't work

hafizidev avatar Apr 16 '21 02:04 hafizidev

Does it work for you:

adb shell input keyevent MEDIA_PLAY_PAUSE

?

On some laptops, Fn is "enabled" by default (customizable from BIOS/UEFI), so you need to press Fn+F9.

rom1v avatar Apr 16 '21 08:04 rom1v

adb shell input keyevent MEDIA_PLAY_PAUSE

Running this works for me. Music paused and played

And I disabled Fn a while back on my laptop, as I am using F2 very frequently for renaming, so this is not the problem for me I

hafizidev avatar Apr 16 '21 10:04 hafizidev

@hafizidev How did you compiled scrcpy including this patch?

rom1v avatar Apr 16 '21 10:04 rom1v

@hafizidev How did you compiled scrcpy including this patch?

I am very sorry, I didn't notice that this is development feature. I use the release version, not development, no wonder it didn't work. Sorry again

hafizidev avatar Apr 21 '21 03:04 hafizidev

Does it work for you:

adb shell input keyevent MEDIA_PLAY_PAUSE

?

On some laptops, Fn is "enabled" by default (customizable from BIOS/UEFI), so you need to press Fn+F9.

What about next track or previous track

samxkevin avatar Mar 31 '24 04:03 samxkevin

Does it work for you:

adb shell input keyevent MEDIA_PLAY_PAUSE

? On some laptops, Fn is "enabled" by default (customizable from BIOS/UEFI), so you need to press Fn+F9.

What about next track or previous track

Checkout Android Key Events docs: https://developer.android.com/reference/android/view/KeyEvent

Sledmine avatar Apr 05 '24 18:04 Sledmine

maybe related: #4080

Background, why this might be not enough on linux systems: On most Desktop environments, the wayland shell/Xwindow manager will receive these button events and handle them theirselves. For sharing actions with the actual applications, so that they can respond to these actions, these applications implement dbus MPRIS. I'm currently looking at an implementation for mpv which looks quite minimal (as minimal as it gets with dbus...) to maybe port this over to scrcpy.

Gottox avatar Jun 12 '24 14:06 Gottox