SwitchDefaultKeyboard.bat 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. @echo off
  2. chcp 65001 >nul
  3. setlocal enabledelayedexpansion
  4. echo ========================================
  5. echo Switch to Sogou Input Method
  6. echo ========================================
  7. echo.
  8. REM Get the directory where this batch file is located
  9. set "SCRIPT_DIR=%~dp0"
  10. set "PROJECT_ROOT=%SCRIPT_DIR%.."
  11. REM Read ADB path from adb-path-config.js using PowerShell
  12. echo [0/5] Reading ADB path from adb-path-config.js...
  13. for /f "delims=" %%i in ('powershell -Command "$content = Get-Content '%PROJECT_ROOT%\adb-path-config.js' -Raw; if ($content -match '\"adb-path\"\s*:\s*''([^'']+)''') { $adbPath = $matches[1]; $fullPath = $adbPath.TrimEnd([char]92) + [char]92 + 'adb.exe'; if (Test-Path $fullPath) { Write-Output $fullPath } else { Write-Output 'adb' } } else { Write-Output 'adb' }"') do set "ADB_PATH=%%i"
  14. if "%ADB_PATH%"=="" set "ADB_PATH=adb"
  15. echo Using ADB: %ADB_PATH%
  16. echo.
  17. REM Set fixed device address
  18. set "DEVICE_ADDRESS=192.168.2.5:5555"
  19. set "USE_DEVICE_OPTION=-s !DEVICE_ADDRESS!"
  20. echo Using device: !DEVICE_ADDRESS!
  21. echo.
  22. echo [1/5] Check if ADB is available...
  23. "%ADB_PATH%" version >nul 2>&1
  24. if errorlevel 1 (
  25. echo Error: ADB not found at: %ADB_PATH%
  26. echo Please check adb-path-config.js and ensure ADB path is correct
  27. pause
  28. exit /b 1
  29. )
  30. echo ADB is available
  31. echo.
  32. echo [2/5] Check connected devices...
  33. echo.
  34. "%ADB_PATH%" devices
  35. echo.
  36. REM Try to connect if not already connected
  37. echo Checking if device !DEVICE_ADDRESS! is connected...
  38. "%ADB_PATH%" !USE_DEVICE_OPTION! get-state >nul 2>&1
  39. if errorlevel 1 (
  40. echo Device not connected, attempting to connect...
  41. "%ADB_PATH%" connect !DEVICE_ADDRESS! >nul 2>&1
  42. timeout /t 2 /nobreak >nul
  43. "%ADB_PATH%" !USE_DEVICE_OPTION! get-state >nul 2>&1
  44. if errorlevel 1 (
  45. echo Error: Cannot connect to device !DEVICE_ADDRESS!
  46. echo.
  47. echo Please ensure:
  48. echo 1. Device is on the same network
  49. echo 2. Run 0-TEST-CONNECT.BAT to test connection first
  50. pause
  51. exit /b 1
  52. )
  53. echo Device connected successfully
  54. ) else (
  55. echo Device already connected
  56. )
  57. echo.
  58. echo.
  59. echo [3/5] Check current default input method...
  60. echo.
  61. for /f "delims=" %%i in ('"%ADB_PATH%" !USE_DEVICE_OPTION! shell settings get secure default_input_method') do set "CURRENT_IME=%%i"
  62. set "CURRENT_IME=!CURRENT_IME: =!"
  63. echo Current default IME: !CURRENT_IME!
  64. echo.
  65. REM Target input method: Sogou Input Method
  66. set "TARGET_IME=com.sohu.inputmethod.sogou/.SogouIME"
  67. REM Check if already using target input method
  68. if "!CURRENT_IME!"=="!TARGET_IME!" (
  69. echo Sogou Input Method is already the default input method.
  70. echo No action needed.
  71. pause
  72. exit /b 0
  73. )
  74. echo [4/5] List available input methods...
  75. echo.
  76. "%ADB_PATH%" !USE_DEVICE_OPTION! shell ime list -s
  77. echo.
  78. echo [5/5] Switch to Sogou Input Method...
  79. echo Setting !TARGET_IME! as default input method...
  80. "%ADB_PATH%" !USE_DEVICE_OPTION! shell ime enable !TARGET_IME!
  81. if errorlevel 1 (
  82. echo Warning: Failed to enable Sogou Input Method
  83. echo Make sure Sogou Input Method is installed on your device
  84. echo.
  85. ) else (
  86. echo Sogou Input Method enabled successfully
  87. echo.
  88. )
  89. "%ADB_PATH%" !USE_DEVICE_OPTION! shell ime set !TARGET_IME!
  90. if errorlevel 1 (
  91. echo Error: Failed to set default input method
  92. pause
  93. exit /b 1
  94. )
  95. echo Default input method set successfully
  96. echo.
  97. echo Verifying current default input method...
  98. for /f "delims=" %%i in ('"%ADB_PATH%" !USE_DEVICE_OPTION! shell settings get secure default_input_method') do set "NEW_IME=%%i"
  99. set "NEW_IME=!NEW_IME: =!"
  100. echo Current default IME: !NEW_IME!
  101. echo.
  102. if "!NEW_IME!"=="!TARGET_IME!" (
  103. echo ========================================
  104. echo Success: Sogou Input Method is now default
  105. echo ========================================
  106. ) else (
  107. echo ========================================
  108. echo Warning: Failed to set Sogou Input Method as default
  109. echo Expected: !TARGET_IME!
  110. echo Current: !NEW_IME!
  111. echo ========================================
  112. )
  113. echo.
  114. pause