-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvirtual_display.bat
More file actions
100 lines (83 loc) · 2.73 KB
/
virtual_display.bat
File metadata and controls
100 lines (83 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
@echo off
setlocal enabledelayedexpansion
:: Windows batch script to create a virtual display on an Android device and use scrcpy to connect to it
:: Function to clean up the virtual display when the script is terminated
:cleanup
echo Cleaning up...
echo Removing the virtual display...
adb shell settings put global overlay_display_devices none
echo Virtual display removed.
goto :eof
:: Check if adb is available
where adb >nul 2>&1
if %ERRORLEVEL% neq 0 (
echo Error: adb is not installed or not in PATH. Please install Android Debug Bridge.
pause
exit /b 1
)
:: Check if device is connected
adb devices | findstr "device$" >nul
if %ERRORLEVEL% neq 0 (
echo Error: No Android device connected. Please connect a device and try again.
pause
exit /b 1
)
:: Function to get the list of display IDs and save them to a temporary file
:get_display_ids
echo Getting display IDs...
adb shell dumpsys display | findstr "mDisplayId=" > display_ids_temp.txt
exit /b 0
:: Get initial display IDs
call :get_display_ids
set "initial_displays=display_ids_temp.txt"
:: Create a virtual display on the Android device
echo Creating a virtual display...
adb shell settings put global overlay_display_devices 1920x1080/240
:: Wait for the new display to be recognized
echo Waiting for display to be created...
timeout /t 2 >nul
:: Get new display IDs
call :get_display_ids
set "new_displays=display_ids_temp.txt"
:: Find the new display ID
echo Finding the secondary display ID...
set "secondary_display_id="
for /f "tokens=1 delims==" %%a in ('adb shell dumpsys display ^| findstr "mDisplayId="') do (
set "display_id=%%a"
set "display_id=!display_id:mDisplayId=!"
set "display_id=!display_id: =!"
findstr "!display_id!" %initial_displays% >nul
if !ERRORLEVEL! neq 0 (
set "secondary_display_id=!display_id!"
)
)
if not defined secondary_display_id (
echo Failed to detect the new display ID.
call :cleanup
del display_ids_temp.txt
pause
exit /b 1
) else (
echo Detected secondary display ID: !secondary_display_id!
)
:: Clean up temporary files
del display_ids_temp.txt
:: Check if scrcpy is available
where scrcpy >nul 2>&1
if %ERRORLEVEL% neq 0 (
echo Error: scrcpy is not installed or not in PATH. Please install scrcpy.
call :cleanup
pause
exit /b 1
)
:: Start scrcpy with the provided options and detected display ID
echo Starting scrcpy on the virtual display...
start "" scrcpy -b 24M --window-title="Pixel" --max-fps=60 --no-audio --display-id !secondary_display_id!
echo.
echo Virtual display is running. Close this window to terminate and clean up.
echo.
:: Wait for user to close the window
pause
:: The cleanup function will be called when the script exits
call :cleanup
exit /b 0