目录

Scrcpy Android投屏神器

Scrcpy 简介

应用程序可显示和控制通过USB(或通过TCP / IP)连接的Android设备。它不需要任何根访问权限。它适用于GNU / Linux,Windows和macOS。

github地址:https://github.com/Genymobile/scrcpy

配置环境

  1. 安装adb服务,使用数据线连接自己的安卓设备,并查看自己的安卓设备:
1
2
3
4
5
6
7
8
9
sudo apt-get install android-tools-adb
adb start-server
$ lsusb
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 005: ID 0bda:0821 Realtek Semiconductor Corp.
Bus 001 Device 004: ID 0bda:0129 Realtek Semiconductor Corp. RTS5129 Card Reader Controller
Bus 001 Device 003: ID 13d3:a745 IMC Networks
Bus 001 Device 054: ID `24ae:1813`
...

找到自己的安卓设备哪一行,24ae1813在下面会用到。

  1. 创建设备文件:

下面命令中的名称71-android是自定义的,我的这个代表安卓7.1的意思。

1
2
3
echo 0x12d1 > ~/.android/adb_usb.ini
touch /etc/udev/rules.d/71-android.rules
gedit /etc/udev/rules.d/71-android.rules

将以下内容写入刚刚创建的文件,注意,下面的24ae1813要改成自己的安卓设备的id(见上):

SUBSYSTEM"usb", ATTRS{idVendor}“24ae”, ATTRS{idProduct}==“1813”, MODE=“0666”

更改文件权限:

1
chmod 666 /etc/udev/rules.d/90-android.rules
  1. 重启 ADB 服务:
1
2
3
service udev restart
adb kill-server
adb start-server

Scrcpy 安装与使用

安装:

1
2
3
4
# 使用snap安装
sudo snap install scrcpy
# 或者
apt install scrcpy

列出设备:

1
scrcpy.adb devices

开始投屏:

1
scrcpy

设置无线连接Android设备

:information_source:先使用数据线将手机和电脑连接并在手机端开启「开发者选项」及「USB 调试」

1
2
# 开启手机端口
adb tcpip 6666

拔出数据线,开启无线连接:

1
adb connect 192.168.8.154:6666

192.168.8.154为你Android设备的IP地址,可以通过路由器后台获取或者在手机上使用相关软件进行获取。

启动 scrcpy :

1
scrcpy

Scrcpy 快捷键

ActionShortcutShortcut (macOS)
Switch fullscreen modeCtrl+fCmd+f
Rotate display leftCtrl+ (left)Cmd+ (left)
Rotate display rightCtrl+ (right)Cmd+ (right)
Resize window to 1:1 (pixel-perfect)Ctrl+gCmd+g
Resize window to remove black bordersCtrl+x | Double-click¹Cmd+x | Double-click¹
Click on HOMECtrl+h | Middle-clickCtrl+h | Middle-click
Click on BACKCtrl+b | Right-click²Cmd+b | Right-click²
Click on APP_SWITCHCtrl+sCmd+s
Click on MENUCtrl+mCtrl+m
Click on VOLUME_UPCtrl+ (up)Cmd+ (up)
Click on VOLUME_DOWNCtrl+ (down)Cmd+ (down)
Click on POWERCtrl+pCmd+p
Power onRight-click²Right-click²
Turn device screen off (keep mirroring)Ctrl+oCmd+o
Turn device screen onCtrl+Shift+oCmd+Shift+o
Rotate device screenCtrl+rCmd+r
Expand notification panelCtrl+nCmd+n
Collapse notification panelCtrl+Shift+nCmd+Shift+n
Copy device clipboard to computerCtrl+cCmd+c
Paste computer clipboard to deviceCtrl+vCmd+v
Copy computer clipboard to device and pasteCtrl+Shift+vCmd+Shift+v
Enable/disable FPS counter (on stdout)Ctrl+iCmd+i

¹Double-click on black borders to remove them. ²Right-click turns the screen on if it was off, presses BACK otherwise.

参考链接