Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forward mouse move without button pressed to device #3070

Closed
1 task done
yume-chan opened this issue Feb 27, 2022 · 15 comments
Closed
1 task done

Forward mouse move without button pressed to device #3070

yume-chan opened this issue Feb 27, 2022 · 15 comments

Comments

@yume-chan
Copy link
Contributor

Recently I'm implementing --forward-all-clicks option for my client, and I tried to use ACTION_HOVER_MOVE action for mouse movement events without button pressed. I was surprised that many Apps will react to it

Related code: https://github.com/yume-chan/ya-webadb/blob/36d44243cc1b40dcaa83c77b0b423add5202c8f7/apps/demo/pages/scrcpy.tsx#L676-L681

handlePointerMove = (e: React.PointerEvent<HTMLDivElement>) => {
    this.injectTouch(
        e.buttons === 0 ? AndroidMotionEventAction.HoverMove : AndroidMotionEventAction.Move,
        e
    );
};

180583c0-2d95-4607-ac1f-14b0349da660
(Google Chrome)

b829b9db-e512-434c-bf6b-3f44f910df0d
(Samsung One UI Settings)

8f27b340-30bc-47c7-9c8e-65e299a341c8
(Google Play Store)

8db70db7-04fd-4802-a282-a2efba5b3d21
(Twitter, notice second bottom bar button)

It's not very useful, and I'm not actually requesting you to implement it. Just want to let you know it's possible.

@rom1v
Copy link
Collaborator

rom1v commented Feb 27, 2022

But the mouse is not visible on the device, right? (contrary to scrcpy --hid-mouse)

@yume-chan
Copy link
Contributor Author

yume-chan commented Feb 28, 2022

Correct.

I haven't used the HID mouse emulation mode, I know Android will display its own mouse cursor, but do you capture the mouse and hide the cursor on computer? Otherwise there will be two cursors?

In my method injecting hover move, the mouse is still in absolute mode, so hover state on Android Apps is always under the computer mouse cursor, and Android won't display its own cursor.

@rom1v
Copy link
Collaborator

rom1v commented Feb 28, 2022

but do you capture the mouse and hide the cursor on computer?

Yes.

In my method injecting hover move, the mouse is still in absolute mode, so hover state on Android Apps is always under the computer mouse cursor, and Android won't display its own cursor.

OK, I will try, and maybe enable it or add an option.

@hammad2224
Copy link

hammad2224 commented Mar 5, 2022

just like shooting games if we could do the mouse move like appPower mirror.
we can play alot of games with this software.
Can you please implement this feature i am waiting from last 2 years for this feature so i could play shooting games on it.

Also please let us know how to donate to your project

@rom1v
Copy link
Collaborator

rom1v commented Mar 6, 2022

and I tried to use ACTION_HOVER_MOVE action for mouse movement events without button pressed. I was surprised that many Apps will react to it

I made a quick test:

diff --git a/app/src/mouse_inject.c b/app/src/mouse_inject.c
index 2e89de9a..1d5a975b 100644
--- a/app/src/mouse_inject.c
+++ b/app/src/mouse_inject.c
@@ -58,17 +58,13 @@ convert_touch_action(enum sc_touch_action action) {
 static void
 sc_mouse_processor_process_mouse_motion(struct sc_mouse_processor *mp,
                                     const struct sc_mouse_motion_event *event) {
-    if (!event->buttons_state) {
-        // Do not send motion events when no click is pressed
-        return;
-    }
-
     struct sc_mouse_inject *mi = DOWNCAST(mp);
 
     struct sc_control_msg msg = {
         .type = SC_CONTROL_MSG_TYPE_INJECT_TOUCH_EVENT,
         .inject_touch_event = {
-            .action = AMOTION_EVENT_ACTION_MOVE,
+            .action = event->buttons_state ? AMOTION_EVENT_ACTION_MOVE
+                                           : AMOTION_EVENT_ACTION_HOVER_MOVE,
             .pointer_id = POINTER_ID_MOUSE,
             .position = event->position,
             .pressure = 1.f,

On a Nexus 5, it has no effect.
On a OnePlus 7 Pro, it only "works" in the notification panel, but not in settings or context menus…

Maybe some ACTION_HOVER_ENTER and ACTION_HOVER_EXIT are necessary?

just like shooting games if we could do the mouse move like appPower mirror.
we can play alot of games with this software.

How does APowerMirror send mouse event? (I've never used it)

@hammad2224
Copy link

hammad2224 commented Mar 6, 2022

i think they use the swap and merge it with mouse move. like key mapping along with mouse mapping
here is the github repo which also allow mouse swap and multiple key combinations.
Basically we need key mapping functionality for gaming experience like LD Player Smartgaga
https://github.com/BobbleKeyboard/android_touch

@yume-chan
Copy link
Contributor Author

On a Nexus 5, it has no effect.
On a OnePlus 7 Pro, it only "works" in the notification panel, but not in settings or context menus…

Yes, the ultimate outcome is decided by each App.

Maybe some ACTION_HOVER_ENTER and ACTION_HOVER_EXIT are necessary?

I didn't try them. I found ACTION_HOVER_MOVE works also by accident. Maybe more Apps will work when having them.

@yume-chan
Copy link
Contributor Author

Samsung S Pen supports hovering, so Samsung One UI might be the best system in supporting hover state.

I did more tests around ACTION_HOVER_ENTER and ACTION_HOVER_EXIT, looks like no one cares about them.

One thing I found is that when another pointer is DOWN, the hovering pointer must be removed, otherwise the new pointer won't do anything. With a real OTG mouse, touching the screen with finger will automatically deactivate the mouse.

@AndroidDeveloperLB
Copy link

Any news about this?

On Android Studio, it's implemented right now, so when you hover with your mouse over (probably almost and not all) anything , it makes an effect for it accordingly.

@rom1v
Copy link
Collaborator

rom1v commented Jun 21, 2024

I just re-tested this patch: #3070 (comment)

It seems to work on my Pixel 8. Could you please test?

If that works, we can add an option, either:

  • --forward-hover to enable the feature
  • enable hover by default, and add --no-forward-hover to restore the previous behavior

(other suggestions for naming are welcome)

@AndroidDeveloperLB
Copy link

AndroidDeveloperLB commented Jun 21, 2024

@rom1v I can test on Pixel 6 with Android 14 and Honor Magic 4 pro with Android 14.
If you want me to check, please provide me a link to the ScrCpy binaries that have this feature.

@rom1v
Copy link
Collaborator

rom1v commented Jun 21, 2024

@AndroidDeveloperLB Here is a binary with the patch above:

@AndroidDeveloperLB
Copy link

@rom1v Thank you.
Works fine for Honor Magic4 pro (though for settings they probably didn't add hovering effect for some reason).
Also works fine for Pixel 6.

Now I wonder if you will make it the default behavior or not, and if it has any danger in using it...
Is it similar to what Google did? If so, maybe it's safe...

rom1v added a commit that referenced this issue Jun 29, 2024
Also add an option --no-mouse-hover to get the old behavior.

Fixes #2743 <#2743>
Fixes #3070 <#3070>
@rom1v
Copy link
Collaborator

rom1v commented Jun 29, 2024

Implemented by #5039.

@rom1v rom1v closed this as completed in 7633228 Jun 29, 2024
@AndroidDeveloperLB
Copy link

@rom1v Thank you!
I hope some day Google will pay you a lot for this tool, and users will also have it official, like what Apple is doing today with their mirroring solution.

FreedomBen pushed a commit to FreedomBen/scrcpy that referenced this issue Aug 2, 2024
Also add an option --no-mouse-hover to get the old behavior.

Fixes Genymobile#2743 <Genymobile#2743>
Fixes Genymobile#3070 <Genymobile#3070>
PR Genymobile#5039 <Genymobile#5039>
Gottox pushed a commit to Gottox/scrcpy that referenced this issue Sep 29, 2024
Also add an option --no-mouse-hover to get the old behavior.

Fixes Genymobile#2743 <Genymobile#2743>
Fixes Genymobile#3070 <Genymobile#3070>
PR Genymobile#5039 <Genymobile#5039>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants