--- name: android_input_keyevent kind: function lang: bash domain: infra version: "1.0.0" purity: impure signature: "android_input_keyevent([--serial ] key: string)" description: "Send key event via adb shell input keyevent. Accepts aliases (BACK, HOME, POWER, ENTER, MENU, RECENT_APPS, VOLUME_UP, VOLUME_DOWN), raw numeric codes, or explicit KEYCODE_* names." tags: [android, adb, input, keyevent, ui-test] params: - name: "--serial " desc: "Optional target device/emulator serial. If omitted, adb_pick_serial resolves the single connected device." - name: "key" desc: "Keycode: short alias (BACK/HOME/POWER/ENTER/MENU/RECENT_APPS/VOLUME_UP/VOLUME_DOWN), raw number (e.g. 4, 26), or explicit KEYCODE_* name." output: "Stdout 'key: on '." uses_functions: ["adb_wsl_bash_infra"] uses_types: [] returns: [] returns_optional: false error_type: "error_go_core" imports: [] tested: false tests: [] test_file_path: "" file_path: "bash/functions/infra/android_input_keyevent.sh" notes: "Lista completa de keycodes: https://developer.android.com/reference/android/view/KeyEvent. Exit 3 si adb_pick_serial falla (ningun device o ambiguo sin --serial)." --- ## Ejemplo ```bash # Pulsar BACK en el unico device conectado android_input_keyevent BACK # Pulsar HOME en un emulador especifico android_input_keyevent --serial emulator-5554 HOME # Codigo numerico directo android_input_keyevent 26 # POWER # KEYCODE_* explicito android_input_keyevent KEYCODE_DPAD_CENTER ``` ## Notas Aliases resueltos internamente: | Alias | KEYCODE | |--------------|-----------------------| | BACK | KEYCODE_BACK | | HOME | KEYCODE_HOME | | POWER | KEYCODE_POWER | | ENTER | KEYCODE_ENTER | | MENU | KEYCODE_MENU | | RECENT_APPS | KEYCODE_APP_SWITCH | | VOLUME_UP | KEYCODE_VOLUME_UP | | VOLUME_DOWN | KEYCODE_VOLUME_DOWN | Si el argumento no coincide con ningun alias y no es numerico, se construye `KEYCODE_` para pasarlo directo a `adb shell input keyevent`. Exit codes: 1 = keycode vacio, 3 = fallo de `adb_pick_serial` (ningun device o ambiguo).