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

Add HID keyboard simulation via USB HID over AoAv2 #2632

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,12 @@ Install the required packages from your package manager.

```bash
# runtime dependencies
sudo apt install ffmpeg libsdl2-2.0-0 adb
sudo apt install ffmpeg libsdl2-2.0-0 adb libusb-1.0-0

# client build dependencies
sudo apt install gcc git pkg-config meson ninja-build libsdl2-dev \
libavcodec-dev libavdevice-dev libavformat-dev libavutil-dev
libavcodec-dev libavdevice-dev libavformat-dev libavutil-dev\
libusb-dev

# server build dependencies
sudo apt install openjdk-11-jdk
Expand All @@ -114,7 +115,7 @@ pip3 install meson
sudo dnf install https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm

# client build dependencies
sudo dnf install SDL2-devel ffms2-devel meson gcc make
sudo dnf install SDL2-devel ffms2-devel libusb-devel meson gcc make

# server build dependencies
sudo dnf install java-devel
Expand Down Expand Up @@ -159,7 +160,8 @@ install the required packages:
```bash
# runtime dependencies
pacman -S mingw-w64-x86_64-SDL2 \
mingw-w64-x86_64-ffmpeg
mingw-w64-x86_64-ffmpeg \
mingw-w64-x86_64-libusb

# client build dependencies
pacman -S mingw-w64-x86_64-make \
Expand All @@ -173,7 +175,8 @@ For a 32 bits version, replace `x86_64` by `i686`:
```bash
# runtime dependencies
pacman -S mingw-w64-i686-SDL2 \
mingw-w64-i686-ffmpeg
mingw-w64-i686-ffmpeg \
mingw-w64-i686-libusb

# client build dependencies
pacman -S mingw-w64-i686-make \
Expand All @@ -197,7 +200,7 @@ Install the packages with [Homebrew]:

```bash
# runtime dependencies
brew install sdl2 ffmpeg
brew install sdl2 ffmpeg libusb

# client build dependencies
brew install pkg-config meson
Expand Down
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,29 @@ scrcpy --crop 1224:1440:0:0 # 1224x1440 at offset (0,0)

If `--max-size` is also specified, resizing is applied after cropping.

#### USB HID over AOAv2

Scrcpy can simulate a USB physical keyboard on Android to provide better input
experience, you need to connect your device via USB, not wireless.

However, due to some limitation of libusb and WinUSB driver, you cannot use HID
over AOAv2 on Windows.

Currently a USB serial number is needed to use HID over AOAv2.

```bash
scrcpy --serial XXXXXXXXXXXXXXXX # don't use HID
scrcpy --serial XXXXXXXXXXXXXXXX --input-mode inject # don't use HID
scrcpy --serial XXXXXXXXXXXXXXXX --input-mode hid # try HID and exit if failed
```

Serial number can be found by `adb get-serialno`.

If you are a non-QWERTY keyboard user and using HID mode, please remember to set
correct physical keyboard layout manually in Android settings, because scrcpy
just forwards scancodes to Android device and Android system is responsible for
converting scancodes to correct keycode on Android device (your system does this
on your PC).

#### Lock video orientation

Expand Down
15 changes: 15 additions & 0 deletions app/meson.build
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
src = [
'src/main.c',
'src/adb.c',
'src/aoa_hid.c',
'src/cli.c',
'src/clock.c',
'src/compat.c',
Expand All @@ -12,6 +13,7 @@ src = [
'src/file_handler.c',
'src/fps_counter.c',
'src/frame_buffer.c',
'src/hid_keyboard.c',
'src/input_manager.c',
'src/opengl.c',
'src/receiver.c',
Expand Down Expand Up @@ -54,6 +56,7 @@ if not get_option('crossbuild_windows')
dependency('libavformat'),
dependency('libavcodec'),
dependency('libavutil'),
dependency('libusb-1.0'),
dependency('sdl2'),
]

Expand Down Expand Up @@ -90,8 +93,20 @@ else
include_directories: include_directories(ffmpeg_include_dir)
)

prebuilt_libusb = meson.get_cross_property('prebuilt_libusb')
libusb_bin_dir = meson.current_source_dir() + '/../prebuilt-deps/' + prebuilt_libusb + '/dll'
libusb_include_dir = '../prebuilt-deps/' + prebuilt_libusb + '/include'

libusb = declare_dependency(
dependencies: [
cc.find_library('libusb-1.0', dirs: libusb_bin_dir),
],
include_directories: include_directories(libusb_include_dir)
)

dependencies = [
ffmpeg,
libusb,
sdl2,
cc.find_library('mingw32')
]
Expand Down
10 changes: 10 additions & 0 deletions app/scrcpy.1
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ Start in fullscreen.
.B \-h, \-\-help
Print this help.

.TP
.B \-i, \-\-input\-mode mode
Select input mode for keyboard events.

Possible values are "hid" and "inject".

"hid" uses Android's USB HID over AOAv2 feature to simulate physical keyboard's events, which provides better experience for IME users if supported by you device.

"inject" is the legacy scrcpy way by injecting keycode events on Android, works on most devices and is the default.

.TP
.B \-\-legacy\-paste
Inject computer clipboard text as a sequence of key events on Ctrl+v (like MOD+Shift+v).
Expand Down
Loading