AScript Android Documentation

website·Indexed 31 days ago

https://ascript.cn

Documentation for AScript on Android, featuring screen image capture, OCR, and AI visual recognition via the ascript_ai module. Includes guides on object detection, value extraction using ai.ask_value, action simulation, and integrating YOLO cloud-trained models.

Tokens
13K
Snippets
81
Records
92
Agent score
51%

What's inside AScript

  1. Retrieve and manipulate UI elements using the node selector

    The node module in AScript for Android allows developers to retrieve information about screen elements or perform actions on specific UI controls using a control selector.
    from ascript.android import node
  2. Available AScript Cloud Ecosystem Services

    AScript provides a suite of cloud-based services to support developers, including:

    • Cloud Packaging System (云打包系统)
    • Cloud Activation Code System (云激活码系统)
    • Cloud Model Training (云模型训练)
    • Cloud Database (云数据库)
    • Super Cloud Control System (超级云控系统)
    • Public Network Link System (公网链接系统)
  3. Provide contextual hints for AI recognition

    All AI methods accept an optional hint parameter to provide additional context about what to look for without changing the output format.
    ai.find("确定按钮", hint="在底部弹窗里,不是顶部导航栏那个")
    ai.ask_value("图中算式的结果", value_type=int, hint="只算红框里那一道")
  4. Determine page state and general context

    Use ai.exists() for a boolean check of an element's presence. Use ai.ask_value(..., value_type=bool) for semantic questions about the page state. Use ai.ask() for open-ended descriptions (suitable for logging, not for conditional logic).
    # Check if element exists
    if ai.exists("登录按钮"):
        ai.click("登录按钮")
    
    # Semantic page check
    if ai.ask_value("当前是不是支付成功页", value_type=bool):
        print("Order complete")
    
    # General description
    print(ai.ask("当前是什么页面,用户在做什么"))
  5. Provide contextual hints to AI queries

    Use the hint= parameter in AI methods to provide additional context about what to look for without changing the output format. This helps the model distinguish between similar elements.
    ai.find("Confirm Button", hint="In the bottom popup, not the top navigation bar")
    ai.ask_value("Result of equation", value_type=int, hint="Only calculate the one in the red box")
  6. Install and start AScript HID Device Manager

    Download the HID Device Manager software based on your operating system to manage device connections.
  7. Run AScript in Root or Activation Mode

    For devices requiring higher privileges than standard accessibility:

    • Root Mode: If the device is rooted, select "Run in Root Mode". This provides maximum permissions and is ideal for emulators; no accessibility permissions or specific OS versions are required.
    • Activation Mode: For non-rooted devices, use this mode to temporarily elevate privileges (allowing adb shell commands without a USB cable).
      1. Install the Shizuku app.
      2. Activate Shizuku via ADB or Wireless Debugging.
      3. Open AScript and select "Root or Activation Mode". Note: This mode expires after a device reboot.
  8. Activate and bind HID devices

    To initialize and bind an HID device:

    1. Activation: Ensure 'Developer Mode' is turned OFF before activation to avoid 'error -3'.
    2. Network: Ensure the device and computer are on the same local area network (LAN).
    3. Binding: Start the app, select 'HID Mode', and enter the IP address and Device ID to complete the binding.
  9. Pass images to AI recognition methods

    Most AI methods (except wait()) accept an image= parameter. To save overhead, capture the screen once and reuse the image object for multiple queries. Supported image types include None (auto-capture), PIL.Image, ndarray (OpenCV BGR), or a string file path.
    from ascript.ios import screen
    from ascript.ios.vlm import ascript_ai as ai
    
    # Capture once, reuse multiple times to save cost/time
    shot = screen.capture()
    price = ai.ask_value("Total Price", value_type=float, image=shot)
    count = ai.ask_value("Item Count", value_type=int, image=shot)
  10. Train YOLO models using AScript YOLO Tools

    AScript provides a visual tool (YOLO Tools) to train YOLOv11, v8, and v5 models without needing a manual Python environment. The process involves four main stages:

    1. Setup: Install the AScript Dock, search for "YOLO Tools" (ID: 25) in the AScript STORE, and run it.
    2. Labeling: Use the AScript WEB editor's "YOLO Object Detection -> Label Training" tool to upload images, draw bounding boxes, and export the dataset as a ZIP file.
    3. Training: In YOLO Tools, import the ZIP dataset, select the model version (v5/v8/v11) and size (Nano to XLarge), and start training.
    4. Export: Export the final model in NCNN format.
  11. Find and interact with text on screen using Ocr convenience methods

    The Ocr class provides high-level methods that handle automatic screen capturing and use the current default engine. All these methods support an optional image parameter (Bitmap or cv2 ndarray) to avoid repeated screen captures, and a rect parameter [x, y, x1, y1] to limit the search area.
    from ascript.android.screen import Ocr
    
    # 1. Find the first occurrence of text
    # Returns dict with text, rect, center_x, center_y, confidence or None
    result = Ocr.find("Login")
    
    # 2. Find all occurrences (pass text=None to get all text on screen)
    # Returns list[dict] or None
    all_text = Ocr.find_all()
    
    # 3. Check if text exists
    # Returns True/False
    if Ocr.exists("Login"):
        print("Button exists")
    
    # 4. Find and click text
    # timeout: 0 = try once, >0 = retry until timeout
    Ocr.click("Confirm", timeout=5)
    
    # 5. Wait for text to appear
    # Returns dict or None
    result = Ocr.wait("Loading Complete", timeout=15)
    
    # 6. Wait for text to appear and then click it
    Ocr.wait_click("Start", timeout=10)