ADB Shell Input Events

前端 未结 8 1331
伪装坚强ぢ
伪装坚强ぢ 2020-11-22 11:50

What is the basic difference between adb shell input keyevent and adb shell sendevent? Which one should I use for inputting a character? Are the ke

8条回答
  •  花落未央
    2020-11-22 12:30

    I wrote a simple Powershell script for windows users to map keys to adb shell input events. And controll an Android device remotely over LAN. I don't know if anyone finds it usefull, but I'll share it anyways.

    $ip = 192.168.1.8
    cd D:\Android\android-sdk-windows\platform-tools\; .\adb.exe disconnect $ip; .\adb.exe connect $ip
    $adbKeyNum = @{LeftWindows = "1"; F1 = "3"; Enter = "66"; UpArrow = "19"; DownArrow = "20"; LeftArrow = "21"; RightArrow = "22"; Add = "24";
            Subtract = "25"; Backspace = "4"; P = "26"}
    
    while(1 -eq 1){
        $keyPress = [Console]::ReadKey($true).Key
        if ([string]$keyPress -eq "F10"){
            .\adb.exe disconnect $ip
            exit
        }
        elseif ([string]$keyPress -eq "F6"){
            $string = Read-Host -Prompt 'Input the string: '
            .\adb.exe shell input text $string
        }
        elseif ($adbKeyNum.ContainsKey([string]$keyPress)){
            echo $adbKeyNum.Get_Item([string]$keyPress)
            .\adb.exe shell input keyevent $adbKeyNum.Get_Item([string]$keyPress)
        }
    }
    

提交回复
热议问题