Genymobile / scrcpy

Display and control your Android device
Apache License 2.0
108.77k stars 10.47k forks source link

Is there a way to simulate swipe gesture? #1214

Open DannyDeLoach opened 4 years ago

DannyDeLoach commented 4 years ago

Scrcpy is an amazing tool! It has been extremely helpful for me.

I'm trying to figure out if there is a way to simulate swipe gestures. For example, when I use ctrl+n to see notifications, the only way I can dismiss a notification is to use the left mouse button to click on the notification and then swipe my mouse. This works most of the time, but sometimes it's difficult to click and swipe with the mouse in just the right way. I'm wondering if there is a way (e.g. a key combination or a combination of holding a key while clicking with the mouse, etc.) that would send the swipe gesture to the phone. Similarly, is there a way to simulate a two-finger swipe (up or down)?

Thanks, again, for creating this amazing tool and helping with these questions.

rom1v commented 4 years ago

I'm wondering if there is a way (e.g. a key combination or a combination of holding a key while clicking with the mouse, etc.) that would send the swipe gesture to the phone.

No, it's not implemented.

But it's also not trivial: how many motion events should we generate? Which distance from the first one to the last one? In pixels or in % of the screen? Which speed? Where to start the first event (the current mouse position would be the start, the middle or the end of the swipe)? I guess some values will work in some cases, but not others, and this will be a mess to make it work and maintain :(

Similarly, is there a way to simulate a two-finger swipe (up or down)?

Is some apps, you can just scroll with the mouse. It does not generate a swipe event, but just a scroll event.

Lucaacer commented 4 years ago

You can make a couple of scripts, which are useful if you have got a laptop without a touch screen

This is swipe left

adb shell input swipe 400 400 800 400

and this is swipe right

Btw, this is swipe down

adb shell input swipe 160 0 160 480

and the last one is scroll

adb shell input swipe 200 500 200 0

rom1v commented 4 years ago

input implements swipe if you give them the values, which depend on the context.

Lucaacer commented 4 years ago

Yes, these are the coordinates that work for my Xiaomi MI8 lite.

DannyDeLoach commented 4 years ago

Thank you. This is very helpful. I tried out the various 'adb shell input swipe...' commands listed above. I see how they allow me to send swipe (or scroll, etc.) commands to my phone. The key to using a swipe action to dismiss a notification is knowing the correct coordinates to use. Is there a way to get the current coordinates of where my mouse cursor is located on the emulated phone screen? For example, if I have the mouse cursor positioned over a certain notification and I could get the coordinates of the mouse cursor, then I would know the correct coordinates to use to send a swipe over that notification. Thanks, again, for your help with this.

Lucaacer commented 4 years ago

I suppose it could be done somehow, but you can simply double tap on the touchpad and swipe right in order to dismiss notifications. At least, it works on my old thinkpad t430, which does not have any touchscreen.

DannyDeLoach commented 4 years ago

OK. Thanks. I guess there's not an easy way to get the current position of cursor in relation to the emulated Android screen?

UNIVAC-Colonel-Panic commented 4 years ago

@rom1v wrote:

But it's also not trivial: how many motion events should we generate? Which distance from the first one to the last one? In pixels or in % of the screen? Which speed? Where to start the first event (the current mouse position would be the start, the middle or the end of the swipe)? I guess some values will work in some cases, but not others, and this will be a mess to make it work and maintain :(

Does this mean it is not practical to do #1105 ? Is swiping the only way to change which home screen is displayed? Could you do something like Ctrl + 1, Ctrl + 2?

onguarde commented 3 years ago

suppose we have the mouse-to-gesture mapping,

while holding the alt key modifier,

scrolling up => swipe left scrolling down => swipe right this gesture is useful in many cases,

fullscreen photo carousell switch next/previous. (VERY common) home screen swipe next page (as in OP)

DhrumilDave5 commented 2 years ago

Similarly, is there a way to simulate a two-finger swipe (up or down)?

Yeah even I would like to have that feature, like while some key is pressed, we can do the double swipe.

hitesh7424 commented 1 year ago

Is there a way to get the current coordinates of where my mouse cursor is located on the emulated phone screen?

Enable "Show Pointer Location" (Show Touch Coordinates) in developer options

Mahnas92 commented 1 year ago

I am working remotely for the most time, and it would be nice to be able to test Talkback by enabling gesture emulation. Swiping left/right, and tapping properly. If this is difficult or hard to maintain, maybe consider a special "Talkback mode", where we can use keyboard arrows and Space för swiping and tapping? As it is now, I need to go to the office to test Talkback (strict rules that dev PC & test device cannot leave premises)

Sauvio commented 1 year ago

Can Multitouch be supported in the future releases? Sometimes I'm not used to using a mouse. In that case, I want to operate a laptop touchpad like a device touchscreen

rom1v commented 1 year ago

Multitouch from a touchscreen works.

From a touchpad, It seems complicated, since a touchpad moves the cursor on the computer (each touch involves relative locations), while a touchscreen involves absolute locations on the screen.