@echo off chcp 65001 >nul setlocal enabledelayedexpansion echo ======================================== echo Switch to Sogou Input Method echo ======================================== echo. REM Get the directory where this batch file is located set "SCRIPT_DIR=%~dp0" set "PROJECT_ROOT=%SCRIPT_DIR%.." REM Use ADB from project root adb-tools directory set "ADB_PATH=%PROJECT_ROOT%\adb-tools\adb.exe" REM Check if local ADB exists, otherwise fallback to system PATH if not exist "%ADB_PATH%" ( echo Warning: Local ADB not found at %ADB_PATH% echo Falling back to system PATH... set "ADB_PATH=adb" ) echo [0/5] Using ADB: %ADB_PATH% echo. REM Set fixed device address set "DEVICE_ADDRESS=192.168.2.5:5555" set "USE_DEVICE_OPTION=-s !DEVICE_ADDRESS!" echo Using device: !DEVICE_ADDRESS! echo. echo [1/5] Check if ADB is available... "%ADB_PATH%" version >nul 2>&1 if errorlevel 1 ( echo Error: ADB not found at: %ADB_PATH% echo Please ensure adb.exe exists in %PROJECT_ROOT%\adb-tools\ directory pause exit /b 1 ) echo ADB is available echo. echo [2/5] Check connected devices... echo. "%ADB_PATH%" devices echo. REM Try to connect if not already connected echo Checking if device !DEVICE_ADDRESS! is connected... "%ADB_PATH%" !USE_DEVICE_OPTION! get-state >nul 2>&1 if errorlevel 1 ( echo Device not connected, attempting to connect... "%ADB_PATH%" connect !DEVICE_ADDRESS! >nul 2>&1 timeout /t 2 /nobreak >nul "%ADB_PATH%" !USE_DEVICE_OPTION! get-state >nul 2>&1 if errorlevel 1 ( echo Error: Cannot connect to device !DEVICE_ADDRESS! echo. echo Please ensure: echo 1. Device is on the same network echo 2. Run 0-TEST-CONNECT.BAT to test connection first pause exit /b 1 ) echo Device connected successfully ) else ( echo Device already connected ) echo. echo. echo [3/5] Check current default input method... echo. for /f "delims=" %%i in ('"%ADB_PATH%" !USE_DEVICE_OPTION! shell settings get secure default_input_method') do set "CURRENT_IME=%%i" set "CURRENT_IME=!CURRENT_IME: =!" echo Current default IME: !CURRENT_IME! echo. REM Target input method: Sogou Input Method set "TARGET_IME=com.sohu.inputmethod.sogou/.SogouIME" REM Check if already using target input method if "!CURRENT_IME!"=="!TARGET_IME!" ( echo Sogou Input Method is already the default input method. echo No action needed. pause exit /b 0 ) echo [4/5] List available input methods... echo. "%ADB_PATH%" !USE_DEVICE_OPTION! shell ime list -s echo. echo [5/5] Switch to Sogou Input Method... echo Setting !TARGET_IME! as default input method... "%ADB_PATH%" !USE_DEVICE_OPTION! shell ime enable !TARGET_IME! if errorlevel 1 ( echo Warning: Failed to enable Sogou Input Method echo Make sure Sogou Input Method is installed on your device echo. ) else ( echo Sogou Input Method enabled successfully echo. ) "%ADB_PATH%" !USE_DEVICE_OPTION! shell ime set !TARGET_IME! if errorlevel 1 ( echo Error: Failed to set default input method pause exit /b 1 ) echo Default input method set successfully echo. echo Verifying current default input method... for /f "delims=" %%i in ('"%ADB_PATH%" !USE_DEVICE_OPTION! shell settings get secure default_input_method') do set "NEW_IME=%%i" set "NEW_IME=!NEW_IME: =!" echo Current default IME: !NEW_IME! echo. if "!NEW_IME!"=="!TARGET_IME!" ( echo ======================================== echo Success: Sogou Input Method is now default echo ======================================== ) else ( echo ======================================== echo Warning: Failed to set Sogou Input Method as default echo Expected: !TARGET_IME! echo Current: !NEW_IME! echo ======================================== ) echo. pause