Clear text in the currently focused input field. Args: device_id: Optional HDC device ID for multi-device setups. Note: This method uses repeated delete key events to clear text. For HarmonyOS, you might also use select all + delete for better efficiency.
(device_id: str | None = None)
| 64 | |
| 65 | |
| 66 | def clear_text(device_id: str | None = None) -> None: |
| 67 | """ |
| 68 | Clear text in the currently focused input field. |
| 69 | |
| 70 | Args: |
| 71 | device_id: Optional HDC device ID for multi-device setups. |
| 72 | |
| 73 | Note: |
| 74 | This method uses repeated delete key events to clear text. |
| 75 | For HarmonyOS, you might also use select all + delete for better efficiency. |
| 76 | """ |
| 77 | hdc_prefix = _get_hdc_prefix(device_id) |
| 78 | # Ctrl+A to select all (key code 2072 for Ctrl, 2017 for A) |
| 79 | # Then delete |
| 80 | _run_hdc_command( |
| 81 | hdc_prefix + ["shell", "uitest", "uiInput", "keyEvent", "2072", "2017"], |
| 82 | capture_output=True, |
| 83 | text=True, |
| 84 | ) |
| 85 | _run_hdc_command( |
| 86 | hdc_prefix + ["shell", "uitest", "uiInput", "keyEvent", "2055"], # Delete key |
| 87 | capture_output=True, |
| 88 | text=True, |
| 89 | ) |
| 90 | |
| 91 | |
| 92 | def detect_and_set_adb_keyboard(device_id: str | None = None) -> str: |
nothing calls this directly
no test coverage detected