-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
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
HID support on Windows #2773
Comments
Hi rom, If I use the default mode and click x=200,y=300 with my mouse on scrcpy, |
Scrcpy does not call |
Using this project as a base, I've been able to put together a quick and dirty proof of concept that can inject HID mouse motion events to my Pixel 6 from Windows 10. Console output looks like this when run:
On the phone, you'll see a dialog about an accessory app and then after the last There are still some issues to iron out though, namely that I can't get it to coexist with an The AOAv1 documentation mentions that PIDs with ADB support expose an interface that handles ADB communication. For AOAv2 these are PIDs 0x2D03 and 0x2D05. By comparing the descriptors from before and after entering accessory mode (listed below), I can see that my Pixel 6 with accessory mode PID 0x2D05 has what looks like an ADB interface as its last (bInterfaceNumber 3), but how to make use of it is something I have yet to explore. Hope this can be of some use! Before, with just one interface, which I assume is for ADB:
After, with 4 interfaces, the last of which has a very similar descriptor to the ADB descriptor above:
|
Hi @vsutardja, Thank you for our investigations. By looking at the source code of linux-adk, the principle is similar to what scrcpy does. The problem I encounter is that I always get "Access denied" when opening a device with libusb on Windows. I updated the initial post of this thread to provide more details. Could you try this branch (
Scrcpy does not rely on
Instead, it just considers all the available USB devices having a serial and which could be opened (and this mechanism works pretty well when the devices could be opened). |
Hi Romain, Thanks for taking a look! Interestingly enough, the On a Windows 10 PC running build 19041.1.amd64fre.vb_release.191206-1406 connected to a 2019 Amazon Fire 7:
On a Macbook Pro running Windows 10 through Boot Camp, also build 19041.1.amd64fre.vb_release.191206-1406, connected to a Pixel 6:
I have a OnePlus 5T that I can try as well later tonight. This might be a dumb question but did you make sure to run
I think there may be a slight misconception here, if I'm understanding correctly:
You can see in the working debug output above that neither the Amazon Fire 7 nor the Pixel 6 have a VID:PID matching the header file definitions either. This is expected - by default a device just presents its manufacturer VID:PID, not an AOA-compliant one. Not only is this manufacturer VID:PID interface sufficient to query AOA support and start accessory mode, it's actually the sole case where we even need to do so. That is, if the VID:PID already matches the AOA spec, then the device is guaranteed to support AOA, as it is already operating in accessory mode. You're certainly right that USB debugging needs to be enabled on the device (at least that's been my experience so far). However, an actual adb connection opens and occupies the device, preventing other processes such as scrcpy from doing so. |
Wow, indeed! 🎉 That's was my problem for years! I had never been able to connect to an Android device using libusb on Windows. However, this is a huge restriction: for example |
Though I'm personally happy just using it in OTG mode, I completely agree. The docs mention that at least for PIDs 2D03 and 2D05, there should be an ADB interface available even in accessory mode, which I think is borne out by the descriptors included in my first comment. How to actually use said interface is another issue entirely. Since only one process can hold the device handle open at any given time, the only option I can think of would be to re-implement the ADB protocol through libusb within scrcpy, which I could easily understand being considered out-of-scope for this project. However, if there is any interest in pursuing this approach, a quick search did turn up a bit of prior art - see cstyan's protocol documentation and cgutman's Java library implementation - although I'm not sure how up-to-date they are. |
Many developers use scrcpy for Android development, so FYI, I asked on libusb: libusb/libusb#1065. |
I opened a PR to support We could investigate using libusbk to support HID keyboard and mouse even if adb is running (to support HID + mirroring on Windows): https://github.com/libusb/libusb/wiki/Windows#driver-installation |
I had the same idea re: leveraging libusbK, since it purports to support concurrent connections from multiple applications. A quick initial test replacing the driver resulted in scrcpy otg mode still working, but adb not being able to find the device at all.
|
I think I tried every driver for my Galaxy S9+ and none works, driver except WinUSB are not stable yet. |
Going back to the idea of If I'm interpreting this document correctly, the Here's a supposed drop-in server replacement implemented in Go: https://github.com/danielpaulus/go-adb |
@vsutardja That's interesting, but then closing scrcpy would close the adb daemon, and running several scrcpy instances would not work correctly. |
I'm not sure what this thread is about. Is it about adding support for Unicode keys on Windows? |
Almost 1 year ago this topic but, when I read and understood "Use Scrcpy mirroring while using --otg, on Windows", I remembered that this is possible. It's a gimmick but it works. Of course, there's that little Scrcpy window when in --otg mode that can't stay off the screen. As said, this is a gimmick. |
I like this idea, it does seem to work. |
#2632 added support for HID keyboards, using libusb. It is currently only supported on Linux (because it just works).
Here is a branch where libusb support is enabled for Windows (and the libusb dependency added to the release/build process):
libusb-windows
The problem we face is that the access to the device is always denied:
If you know how to make it work, your help is welcome.
Checkout the
libusb-windows
branch, then follow the BUILD instructionsFor simplicity, here is a prebuilt server for this branch (so that you just have to build the client, it's explained in the BUILD instructions):
scrcpy-server
sha256:7914f0ba2abeac3d4d5b072a4f01a3b5707aea0c8cf64a3f72aeb6f4ec0e0c09The text was updated successfully, but these errors were encountered: