### Getting Started Steps Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/INDEX.md Provides a concise step-by-step guide for getting started with the uiautomation-rs library, including reading the README, configuration, referencing API files, and using examples. ```markdown 1. **Read:** `/workspace/home/output/README.md` 2. **Configure:** Follow setup in `configuration.md` 3. **Reference:** Use appropriate `api-reference/*.md` file 4. **Look up:** Types in `types.md`, errors in `errors.md` 5. **Code:** Start building with examples as templates ``` -------------------------------- ### Multiple Processes Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/api-reference/processes.md Launches and manages multiple processes concurrently. This example starts both Notepad and Calculator and waits for both to close. ```rust use uiautomation::processes::Process; fn main() -> Result<(), Box> { // Launch multiple applications let notepad = Process::create("notepad.exe")?; let calculator = Process::create("calc.exe")?; // Do work with both... // Wait for both to close notepad.wait()?; calculator.wait()?; println!("All processes closed"); Ok(()) } ``` -------------------------------- ### New User Documentation Path Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/INDEX.md Guides new users through the documentation, suggesting a reading order starting with the README, configuration, core API, types, and errors. This ensures a structured learning experience. ```markdown 1. Start with **README.md** 2. Read **configuration.md** to set up 3. Read **api-reference/core.md** to understand main classes 4. Reference **types.md** as needed 5. Consult **errors.md** for error handling ``` -------------------------------- ### Automation Flow with Process Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/api-reference/processes.md Integrates process management with UI automation. This example starts Notepad, finds its window using UI automation, types text, and saves the file. ```rust use uiautomation::{UIAutomation, processes::Process}; fn main() -> Result<(), Box> { // Start Notepad let _notepad = Process::create("notepad.exe")?; // Get UI automation let automation = UIAutomation::new()?; // Find and interact with Notepad let matcher = automation.create_matcher() .classname("Notepad") .timeout(5000); if let Ok(notepad_window) = matcher.find_first() { // Type something notepad_window.send_text("Hello from Rust UI Automation!", 20)?; // Save file notepad_window.send_keys("{ctrl}s", 100)?; } Ok(()) } ``` -------------------------------- ### Simple Process Launch Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/api-reference/processes.md Launches a process and waits for it to complete. This is a basic example of starting an application and ensuring it has closed before continuing. ```rust use uiautomation::processes::Process; fn main() -> Result<(), Box> { // Launch Notepad and wait for it to be ready let notepad = Process::create("notepad.exe")?; // Your UI automation code would go here... // notepad.send_keys(...), etc. // Wait for user to close Notepad notepad.wait()?; println!("Notepad closed"); Ok(()) } ``` -------------------------------- ### WindowControl Example Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/api-reference/controls.md Demonstrates how to use WindowControl to maximize and restore a window. Requires converting a UIElement to a WindowControl. ```rust use uiautomation::controls::WindowControl; let window: WindowControl = element.try_into()?; window.maximize()?; // ... do work ... window.restore()?; ``` -------------------------------- ### Testing setup for uiautomation Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/configuration.md Enable the 'input', 'control', and 'process' features for a testing setup that includes keyboard/mouse simulation and process management. ```toml uiautomation = { version = "0.25", features = ["input", "control", "process"] } ``` -------------------------------- ### Simple Notification Flow Example Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/api-reference/dialogs.md Demonstrates a basic application flow using info and message dialogs for user notifications. ```rust use uiautomation::dialogs::*; fn main() { show_info("Application started", "App"); // Do work... show_message("Work completed", "Status"); show_message("Ready for next task", "Status"); } ``` -------------------------------- ### Install Rust and Target for Windows Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/configuration.md Installs the stable MSVC toolchain and adds the x86_64 Windows target for Rust development. ```bash rustup default stable-msvc rustup target add x86_64-pc-windows-msvc ``` -------------------------------- ### Minimal uiautomation setup Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/configuration.md Configure the uiautomation crate with default-features set to false and an empty features list for a minimal setup focusing on core automation. ```toml uiautomation = { version = "0.25", default-features = false, features = [] } ``` -------------------------------- ### UIAutomation::new() Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/api-reference/core.md Creates a UI Automation client instance with automatic COM library initialization. This is the recommended way to start using the UI Automation client. ```APIDOC ## UIAutomation::new() ### Description Creates a UI Automation client instance with automatic COM library initialization. ### Method `UIAutomation::new()` ### Parameters None ### Returns `Result` - An initialized automation client instance. ### Throws Windows COM errors if initialization fails. ### Example ```rust use uiautomation::UIAutomation; let automation = UIAutomation::new()?; ``` ``` -------------------------------- ### Multi-Step Keyboard Automation Example Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/api-reference/inputs.md Shows a sequence of keyboard operations, including opening a file dialog, typing a filename, and pressing Enter. Includes a manual wait for the dialog to appear. ```rust use uiautomation::UIAutomation; let automation = UIAutomation::new()?; let root = automation.get_root_element()?; // Open file dialog: Ctrl+O root.send_keys("{ctrl}o", 50)?; // Wait for dialog to open (outside this API) std::thread::sleep(std::time::Duration::from_millis(500)); // Type filename root.send_text("myfile.txt", 30)?; // Press Enter to open root.send_keys("{enter}", 0)?; ``` -------------------------------- ### Process with Arguments Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/api-reference/processes.md Launches a process with specific command-line arguments and waits for it to become idle. This example demonstrates opening a file with Notepad. ```rust use uiautomation::processes::Process; fn main() -> Result<(), Box> { let proc = Process::new("notepad.exe") .command("C:\\Users\\Public\\Desktop\\example.txt") .wait_for_idle(3000) .run()?; println!("Notepad opened with file"); proc.wait()?; Ok(()) } ``` -------------------------------- ### Multi-Step Process with Query Yes/No Confirmations Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/api-reference/dialogs.md Use `query_yes_no` for step-by-step confirmations in a process. This example demonstrates sequential prompts and a final `query_yes_no_cancel` for finalization. ```Rust use uiautomation::dialogs::*; fn interactive_process() -> Result<(), String> { show_info("Starting interactive process", "Start"); // Step 1 if !query_yes_no("Do you want to proceed with step 1?", "Step 1") { show_message("Process cancelled at step 1", "Cancelled"); return Ok(()) } show_message("Step 1 completed", "Status"); // Step 2 if !query_yes_no("Do you want to proceed with step 2?", "Step 2") { show_message("Process cancelled at step 2", "Cancelled"); return Ok(()) } show_message("Step 2 completed", "Status"); // Final confirmation match query_yes_no_cancel("Finalize changes?", "Finalize") { Some(true) => { show_info("Changes finalized", "Success"); Ok(()) }, Some(false) => { show_warn("Changes reverted", "Reverted"); Ok(()) }, None => { show_message("Finalization cancelled", "Cancelled"); Err("User cancelled finalization".to_string()) } } } ``` -------------------------------- ### Get Root UI Element Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/api-reference/core.md Retrieves the UI Automation element representing the desktop. Useful for starting navigation. ```rust let automation = UIAutomation::new()?; let root = automation.get_root_element()?; println!("Root element: {}", root.get_name()?); ``` -------------------------------- ### Interact with Button Control Pattern Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/README.md Use control patterns to interact with specific UI element functionalities. This example shows how to get the InvokePattern for a button and invoke it. ```rust use uiautomation::controls::ButtonControl; use uiautomation::patterns::InvokePattern; let button: ButtonControl = element.try_into()?; let invoke = button.get_pattern::()?; invoke.invoke()?; ``` -------------------------------- ### Execute Configured Process Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/api-reference/processes.md Runs the process with the configurations set by the builder methods. Returns an error if the process has already been started. ```rust let proc = Process::new("notepad.exe").run()?; ``` -------------------------------- ### Find Root Element Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/README.md Initialize UIAutomation and get the root element of the UI tree. This is often the starting point for searching other elements. ```rust let automation = UIAutomation::new()?; let root = automation.get_root_element()?; ``` -------------------------------- ### Create Process Builder and Run Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/api-reference/processes.md Creates a process builder that allows configuration before execution. The process is only started when the `run()` method is called. ```rust let proc = Process::new("notepad.exe") .current_directory("C:\\") .wait_for_idle(1000) .run()?; ``` -------------------------------- ### Confirmation Dialog Example Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/api-reference/dialogs.md Illustrates using a query_yes_no dialog to confirm a file deletion action, providing feedback with info or message dialogs. ```rust use uiautomation::dialogs::*; fn delete_file(filename: &str) -> bool { if query_yes_no(&format!("Delete {}?", filename), "Confirm Delete") { // Perform deletion println!("Deleting: {}", filename); show_info(&format!("{} deleted", filename), "Success"); true } else { show_message("Deletion cancelled", "Cancelled"); false } } ``` -------------------------------- ### Create and Launch Process (Wait for Idle) Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/api-reference/processes.md Creates and immediately launches a process, waiting for it to reach an idle state. Use this when you need to ensure the process has completed its initial setup before proceeding. ```rust use uiautomation::processes::Process; let notepad = Process::create("notepad.exe")?; println!("Notepad started"); ``` -------------------------------- ### Capture Desktop Screenshot Source: https://github.com/leexgone/uiautomation-rs/blob/main/README.md Captures the entire desktop, including multi-monitor setups, and saves it as a PNG file. Ensure the `screenshots` module is imported. ```rust use uiautomation::screenshots::Screenshot; use uiautomation::UIAutomation; fn main() { // Capture the entire desktop (multi-monitor supported) let shot = Screenshot::capture_desktop().unwrap(); shot.save_png("desktop.png").unwrap(); // Capture a specific region use uiautomation::types::Rect; let shot = Screenshot::capture_rect(Rect::new(0, 0, 800, 600)).unwrap(); shot.save_bmp("region.bmp").unwrap(); // Capture a UI element directly let automation = UIAutomation::new().unwrap(); let matcher = automation.create_matcher().classname("Notepad"); if let Ok(notepad) = matcher.find_first() { let shot = notepad.screenshot().unwrap(); shot.save_png("notepad.png").unwrap(); } } ``` -------------------------------- ### Initialize UI Automation and Get Root Element Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/README.md This snippet shows how to create a new UIAutomation instance, which includes COM initialization, and then retrieve the root UI element representing the desktop. ```rust let automation = UIAutomation::new()?; let root = automation.get_root_element()?; ``` -------------------------------- ### Process in Different Directory Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/api-reference/processes.md Executes a command in a specified directory. This example runs the `dir` command in `C:\Users\Public` and redirects output to `output.txt`. ```rust use uiautomation::processes::Process; fn main() -> Result<(), Box> { let proc = Process::new("cmd.exe") .current_directory("C:\\Users\\Public") .command("/c dir > output.txt") .run()?; proc.wait()?; println!("Command completed"); Ok(()) } ``` -------------------------------- ### Comprehensive automation setup for uiautomation Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/configuration.md Enable a comprehensive set of features including 'input', 'control', 'pattern', 'process', 'dialog', and 'clipboard' for advanced automation tasks. ```toml uiautomation = { version = "0.25", features = ["input", "control", "pattern", "process", "dialog", "clipboard"] } ``` -------------------------------- ### Get Clipboard Text Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/api-reference/additional-modules.md Retrieves text content from the Windows clipboard. Requires the clipboard to be opened. ```rust let clipboard = Clipboard::open()?; let text = clipboard.get_text()?; println!("Clipboard: {}", text); ``` -------------------------------- ### Maintain UIAutomation-rs Version Compatibility Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/configuration.md Example Cargo.toml snippet to maintain compatibility with previous versions by explicitly enabling specific features. ```toml uiautomation = { version = "0.25", features = ["process", "dialog", "event", "clipboard"] } ``` -------------------------------- ### Process with Exit Code Checking Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/api-reference/processes.md Runs a command, waits for it to complete, and then checks its exit code. This example uses `ipconfig /all` and reports success or failure based on the exit code. ```rust use uiautomation::processes::Process; fn main() -> Result<(), Box> { let proc = Process::new("ipconfig") .command("/all") .wait_for_idle(2000) .run()?; proc.wait()?; match proc.get_exit_code()? { Some(0) => println!("Command succeeded"), Some(code) => println!("Command failed with code {}", code), None => println!("Process still running"), } Ok(()) } ``` -------------------------------- ### UI Automation Integration with Dialogs Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/api-reference/dialogs.md Integrate dialogs with UI automation tasks to provide feedback during automated processes. This example finds Notepad, sends text, and shows status messages. ```Rust use uiautomation::{UIAutomation, dialogs::*}; fn main() -> Result<(), Box> { let automation = UIAutomation::new()?; let root = automation.get_root_element()?; // Find target element let matcher = automation.create_matcher() .classname("Notepad"); match matcher.find_first() { Ok(element) => { show_info("Notepad found, automating input...", "Status"); element.send_text("Automated text input", 20)?; show_message("Text entered successfully", "Done"); Ok(()) }, Err(_) => { show_error("Notepad not found. Please open it first.", "Error"); Err("Notepad not found".into()) } } } ``` -------------------------------- ### Process::new Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/api-reference/processes.md Initializes a process builder without starting the process. This allows you to configure various process properties before execution using chainable builder methods. ```APIDOC ## Process::new ### Description Creates a process builder that will not start until `run()` is called. This allows for configuration of process properties before execution. ### Method `Process::new(command: S) -> Self` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust let proc = Process::new("notepad.exe") .current_directory("C:\") .wait_for_idle(1000) .run()?; ``` ### Response #### Success Response `Process` — A process builder instance. #### Response Example None explicitly defined, but returns a `Process` struct on success. ``` -------------------------------- ### Documentation Notes Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/INDEX.md Highlights key notes about the documentation, including the version, platform, edition, and completeness of API and feature coverage. It also mentions the inclusion of error handling patterns and real-world examples. ```markdown - All documentation generated for version **0.25.0** - Platform: **Windows only** - Edition: **2024** - All public API documented - Feature flags documented - Error handling patterns included - Real-world examples throughout - Cross-references between documents ``` -------------------------------- ### UIElement Tree Traversal Methods Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/api-reference/core.md Provides methods for navigating the UI element tree, such as getting parent, first child, last child, and siblings. ```APIDOC ## `get_parent` Gets the parent element. ### Parameters #### Path Parameters - **element** (UIElement) - Required - Element whose parent to find ### Returns `Result` — Parent element --- ## `get_first_child` Gets the first child element. ### Returns `Result` — First child --- ## `get_last_child` Gets the last child element. ### Returns `Result` — Last child --- ## `get_next_sibling` Gets the next sibling element. ### Returns `Result` — Next sibling --- ## `get_previous_sibling` Gets the previous sibling element. ### Returns `Result` — Previous sibling --- ## `get_next_sibling_at_level` Gets next sibling and descends into it up to specified depth level. ### Returns `Result` — Element at specified level ``` -------------------------------- ### Initialize UI Automation Client Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/api-reference/core.md Creates a UI Automation client instance with automatic COM library initialization. Use this for most scenarios. ```rust use uiautomation::UIAutomation; let automation = UIAutomation::new()?; ``` -------------------------------- ### Initialize UI Automation Client (Direct) Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/api-reference/core.md Creates a UI Automation client without initializing the COM library. Use this if COM is already initialized. ```rust use uiautomation::UIAutomation; let automation = UIAutomation::new_direct()?; ``` -------------------------------- ### Interact with a UI Element Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/README.md This snippet demonstrates common interactions with a UIElement, such as getting its name, sending text input, and performing a click action. Ensure the UIElement is valid and accessible. ```rust let element = automation.get_root_element()?; println!("Name: {}", element.get_name()?); element.send_text("type this", 20)?; element.click(10)?; ``` -------------------------------- ### UIAutomation::new_direct() Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/api-reference/core.md Creates a UI Automation client without initializing the COM library. Use this if COM has already been initialized manually. ```APIDOC ## UIAutomation::new_direct() ### Description Creates a UI Automation client without initializing the COM library. COM must be initialized manually beforehand. ### Method `UIAutomation::new_direct()` ### Parameters None ### Returns `Result` - An initialized automation client instance. ### Throws Windows COM errors if COM is not initialized. ### Example ```rust use uiautomation::UIAutomation; let automation = UIAutomation::new_direct()?; ``` ``` -------------------------------- ### Create Mouse Simulator Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/api-reference/inputs.md Instantiate a new mouse input simulator. ```Rust let mouse = Mouse::new(); ``` -------------------------------- ### Print All UI Elements Recursively Source: https://github.com/leexgone/uiautomation-rs/blob/main/README.md Recursively traverses the UI tree starting from the root element and prints the class name and name of each UI element. Requires the `UIAutomation`, `UIElement`, and `UITreeWalker` traits. ```rust use uiautomation::Result; use uiautomation::UIAutomation; use uiautomation::UIElement; use uiautomation::UITreeWalker; fn main() { let automation = UIAutomation::new().unwrap(); let walker = automation.get_control_view_walker().unwrap(); let root = automation.get_root_element().unwrap(); print_element(&walker, &root, 0).unwrap(); } fn print_element(walker: &UITreeWalker, element: &UIElement, level: usize) -> Result<()> { for _ in 0..level { print!(" ") } println!("{} - {}", element.get_classname()?, element.get_name()?); if let Ok(child) = walker.get_first_child(&element) { print_element(walker, &child, level + 1)?; let mut next = child; while let Ok(sibling) = walker.get_next_sibling(&next) { print_element(walker, &sibling, level + 1)?; next = sibling; } } Ok(()) } ``` -------------------------------- ### Screen Size Retrieval Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/api-reference/inputs.md A utility function to get the dimensions of the primary screen. ```APIDOC ## get_screen_size() ### Description Retrieves the resolution (width and height) of the primary screen. ### Method N/A (Rust function call) ### Endpoint N/A ### Parameters None ### Request Example ```rust use uiautomation::inputs::get_screen_size; let (width, height) = get_screen_size()?; println!("Screen: {}x{}", width, height); ``` ### Response #### Success Response (200) Returns a tuple containing the screen width and height. #### Response Example `(i32, i32)` ``` -------------------------------- ### Documentation Statistics Summary Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/INDEX.md Provides a summary of the documentation's scope, including the number of files, lines of code, examples, and types documented. This gives an overview of the library's completeness. ```markdown - **Total files:** 10 markdown files - **Total lines:** ~15,000+ lines - **Code examples:** 100+ - **Type definitions:** 50+ - **Method signatures:** 200+ - **Enumerations:** 30+ - **Error codes:** 9 standard + Windows integration - **Features documented:** All 9 features - **Controls documented:** All 30+ control types - **Patterns documented:** All major patterns ``` -------------------------------- ### TextPatternRangeEndpoint Enum Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/types.md Represents the start and end points within a text range. ```rust pub enum TextPatternRangeEndpoint { Start = 0, End = 1, } ``` -------------------------------- ### Navigate UI Element Tree Hierarchy Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/README.md This snippet illustrates how to use a UITreeWalker to navigate the UI element hierarchy, specifically by getting the first child of the root element. Ensure the UIAutomation instance is initialized. ```rust let walker = automation.get_control_view_walker()?; let root = automation.get_root_element()?; let first_child = walker.get_first_child(&root)?; ``` -------------------------------- ### Create Keyboard Simulator Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/api-reference/inputs.md Instantiate a new keyboard input simulator. ```Rust let kb = Keyboard::new(); ``` -------------------------------- ### Get Current Mouse Position Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/api-reference/inputs.md Retrieve the current screen coordinates of the mouse cursor. ```Rust use uiautomation::inputs::Mouse; let pos = Mouse::get_position()?; println!("Mouse at: {}", pos); ``` -------------------------------- ### Get Element Name Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/api-reference/core.md Retrieves the display name of a UI element. Ensure the element is valid before calling. ```rust let name = element.get_name()?; println!("Element name: {}", name); ``` -------------------------------- ### Open Notepad and Input Text Source: https://github.com/leexgone/uiautomation-rs/blob/main/README.md Launches Notepad, finds the Notepad window, inputs text into it, and then maximizes the window. Requires the `UIAutomation` and `Process` types, and the `WindowControl` trait. ```rust use uiautomation::core::UIAutomation; use uiautomation::processes::Process; fn main() { Process::create("notepad.exe").unwrap(); let automation = UIAutomation::new().unwrap(); let root = automation.get_root_element().unwrap(); let matcher = automation.create_matcher().from(root).timeout(10000).classname("Notepad"); if let Ok(notepad) = matcher.find_first() { println!("Found: {} - {}", notepad.get_name().unwrap(), notepad.get_classname().unwrap()); notepad.send_keys("Hello,Rust UIAutomation!{enter}", 10).unwrap(); let window: WindowControl = notepad.try_into().unwrap(); window.maximize().unwrap(); } } ``` -------------------------------- ### Recommended UIAutomation-rs Project Configuration Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/configuration.md A Cargo.toml configuration recommending the use of minimal features in production and full features in development/test dependencies. ```toml [dependencies] uiautomation = "0.25" [dev-dependencies] uiautomation = { version = "0.25", features = ["all"] } ``` -------------------------------- ### Get Bounding Rectangle Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/api-reference/core.md Retrieves the bounding rectangle of a UI element, used to determine its position and size on the screen. ```rust let rect = element.get_bounding_rectangle()?; println!("Position: ({}, {}), Size: ({}, {})", rect.get_left(), rect.get_top(), rect.get_width(), rect.get_height()); ``` -------------------------------- ### ValuePattern Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/api-reference/additional-modules.md Provides methods to get and set the value of an element. This is useful for input fields or elements that have a changeable value. ```APIDOC ## ValuePattern Gets/sets element value. ### Description Provides methods to get and set the value of an element. This is useful for input fields or elements that have a changeable value. ### Usage Example ```rust let value = element.get_pattern::()?; value.set_value("new value")?; let current = value.get_value()?; ``` ``` -------------------------------- ### Simulating Keyboard Shortcuts Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/api-reference/inputs.md Demonstrates how to send common keyboard shortcuts like Ctrl+S, Ctrl+P, Ctrl+F, Ctrl+H, Ctrl+Z, and Ctrl+Y using the Keyboard input simulation. ```rust use uiautomation::{UIAutomation, inputs::Keyboard}; let automation = UIAutomation::new()?; let element = automation.get_root_element()?; element.set_focus()?; let kb = Keyboard::new().interval(50); // Save document: Ctrl+S kb.send_keys("{ctrl}s")?; // Print: Ctrl+P kb.send_keys("{ctrl}p")?; // Find: Ctrl+F kb.send_keys("{ctrl}f")?; // Replace: Ctrl+H kb.send_keys("{ctrl}h")?; // Undo: Ctrl+Z kb.send_keys("{ctrl}z")?; // Redo: Ctrl+Y kb.send_keys("{ctrl}y")?; ``` -------------------------------- ### Get Element Name Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/README.md Retrieve the name property of a UI element. This is often used for identifying or logging elements. ```rust let name = element.get_name()?; ``` -------------------------------- ### Get Property Value Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/api-reference/core.md Retrieves the value of any UI property associated with the element. The value is returned as a generic Variant type. ```rust let value = element.get_property_value(UIProperty::Name)?; ``` -------------------------------- ### Get Clickable Point Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/api-reference/core.md Retrieves a screen coordinate point on the element that is guaranteed to be clickable. Returns None if no such point can be found. ```rust let clickable_point = element.get_clickable_point()?; ``` -------------------------------- ### Get Control Type Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/api-reference/core.md Retrieves the control type of a UI element and matches it against known types. Requires importing `ControlType`. ```rust use uiautomation::types::ControlType; let ctrl_type = element.get_control_type()?; match ctrl_type { ControlType::Button => println!("Button"), ControlType::Edit => println!("Text field"), _ => println!("Other control"), } ``` -------------------------------- ### Initialize and Interact with UI Automation Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/README.md This snippet demonstrates the basic workflow of initializing UI Automation, finding a UI element by class name and timeout, and sending text to it. Ensure UI Automation is properly set up in your environment. ```rust use uiautomation::{UIAutomation, UIElement}; fn main() -> Result<(), Box> { // Initialize UI Automation let automation = UIAutomation::new()?; // Get root element (desktop) let root = automation.get_root_element()?; // Find element let matcher = automation.create_matcher() .classname("Notepad") .timeout(5000); if let Ok(element) = matcher.find_first() { println!("Found: {}", element.get_name()?); // Interact with element element.send_text("Hello from Rust!", 20)?; } Ok(()) } ``` -------------------------------- ### Get Content View Walker Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/api-reference/core.md Retrieves the predefined tree walker for content view. Use this for accessing content-oriented elements. ```rust let automation = UIAutomation::new()?; let walker = automation.get_content_view_walker()?; ``` -------------------------------- ### Get Focused UI Element Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/api-reference/core.md Retrieves the UI element that currently has input focus. Useful for interacting with the active element. ```rust let focused = automation.get_focused_element()?; println!("Focused element: {}", focused.get_name()?); ``` -------------------------------- ### Get and Set Element Value Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/api-reference/additional-modules.md Retrieves and sets the value of an element using the ValuePattern. Ensure the element supports this pattern. ```rust let value = element.get_pattern::()?; value.set_value("new value")?; let current = value.get_value()?; ``` -------------------------------- ### Process::create Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/api-reference/processes.md Creates and immediately launches a process, waiting for it to reach an idle state. This is useful when you need to ensure the application has finished its initial startup routines before proceeding. ```APIDOC ## Process::create ### Description Creates and immediately launches a process, waiting for the process to reach an idle state (default 0.5s timeout). Returns immediately if successful. ### Method `Process::create(command: S) -> Result` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust use uiautomation::processes::Process; let notepad = Process::create("notepad.exe")?; println!("Notepad started"); ``` ### Response #### Success Response `Result` — The successfully started process. #### Response Example None explicitly defined, but returns a `Process` struct on success. ``` -------------------------------- ### Get Element Control Type Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/README.md Retrieve the control type of a UI element. This can be useful for differentiating between various UI components. ```rust let type_id = element.get_control_type()?; ``` -------------------------------- ### Keyboard::new Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/api-reference/inputs.md Creates a new keyboard input simulator. This is the entry point for all keyboard-related automation tasks. ```APIDOC ## Keyboard::new ### Description Creates a new keyboard input simulator. ### Method `new()` ### Returns `Self` - A new instance of the Keyboard simulator. ``` -------------------------------- ### Capture Element Screenshot Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/README.md Take a screenshot of a specific UI element. The captured image can then be saved to a file, for example, as a PNG. ```rust let screenshot = element.screenshot()?; screenshot.save_png("element.png")?; ``` -------------------------------- ### Get Element Class Name Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/README.md Retrieve the class name of a UI element. This property is often used in filtering and matching elements. ```rust let class = element.get_classname()?; ``` -------------------------------- ### Project File Structure Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/INDEX.md Illustrates the organization of the uiautomation-rs project, showing the location of the main documentation files and API reference modules. ```text output/ ├── INDEX.md # This file ├── README.md # Start here - Overview and navigation ├── configuration.md # Features, setup, environment ├── types.md # Type definitions and enumerations ├── errors.md # Error codes and handling patterns └── api-reference/ ├── core.md # UIAutomation, UIElement, UITreeWalker, UIMatcher ├── inputs.md # Keyboard and mouse input simulation ├── processes.md # Process creation and management ├── dialogs.md # Message box dialogs ├── controls.md # Control type wrappers └── additional-modules.md # Patterns, events, clipboard, screenshots, filters ``` -------------------------------- ### Testing Framework Configuration with UIAutomation-rs Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/configuration.md A Cargo.toml configuration for setting up an async testing framework with full UI automation support using tokio. ```toml [dev-dependencies] uiautomation = { version = "0.25", features = ["all"] } tokio = { version = "1", features = ["full"] } ``` -------------------------------- ### Find Buttons using TreeScope::Descendants Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/types.md Example of finding all buttons within the descendants of the root element using a property condition. ```rust // Find all buttons in the window let condition = automation.create_property_condition( UIProperty::ControlType, Variant::from(ControlType::Button as i32), None )?; let buttons = root.find_all(TreeScope::Descendants, &condition)?; ``` -------------------------------- ### Generate UIAutomation-rs Documentation Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/configuration.md Commands to generate and open the documentation for the UIAutomation-rs crate, with and without all features. ```bash cargo doc --open cargo doc --all-features --open ``` -------------------------------- ### Minimal UIAutomation-rs Project Configuration Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/configuration.md A basic Cargo.toml configuration for a project using the UIAutomation-rs crate for core UI element access and keyboard input. ```toml [package] name = "my-app" version = "0.1.0" edition = "2024" [dependencies] uiautomation = "0.25" ``` -------------------------------- ### Get Raw View Walker Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/api-reference/core.md Retrieves the tree walker for an unfiltered view of all UI Automation elements. Use this for deep inspection or debugging. ```rust let automation = UIAutomation::new()?; let walker = automation.get_raw_view_walker()?; ``` -------------------------------- ### Get UI Element from Screen Point Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/api-reference/core.md Retrieves the UI element at the specified screen coordinates. Requires a `Point` struct with x and y coordinates. ```rust use uiautomation::types::Point; let automation = UIAutomation::new()?; let point = Point::new(100, 200); let element = automation.element_from_point(point)?; ``` -------------------------------- ### UIMatcher Constructor and Builder Methods Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/api-reference/core.md Details on how to create and configure a UIMatcher for finding UI elements. ```APIDOC ## `UIMatcher::new` Creates a new matcher from an automation instance. ### Parameters #### Path Parameters - **automation** (UIAutomation) - Required - The UIAutomation instance ### Returns `Self` --- ## `UIMatcher::from` Sets the starting element for search (default: root). ### Parameters #### Path Parameters - **element** (UIElement) - Required - The starting element for the search ### Returns `&mut Self` — Self for chaining --- ## `UIMatcher::depth` Sets maximum search depth (default: unlimited). ### Parameters #### Path Parameters - **depth** (usize) - Required - Maximum search depth ### Returns `&mut Self` — Self for chaining --- ## `UIMatcher::timeout` Sets timeout in milliseconds (default: 1000). ### Parameters #### Path Parameters - **milliseconds** (u32) - Required - Timeout duration in milliseconds ### Returns `&mut Self` — Self for chaining --- ## `UIMatcher::classname` Filters by class name (e.g., "Notepad"). ### Parameters #### Path Parameters - **classname** (&str) - Required - The class name to filter by ### Returns `&mut Self` — Self for chaining --- ## `UIMatcher::name` Filters by element name. ### Parameters #### Path Parameters - **name** (&str) - Required - The element name to filter by ### Returns `&mut Self` — Self for chaining --- ## `UIMatcher::control_type` Filters by control type. ### Parameters #### Path Parameters - **control_type** (ControlType) - Required - The control type to filter by ### Returns `&mut Self` — Self for chaining --- ## `UIMatcher::automation_id` Filters by automation ID. ### Parameters #### Path Parameters - **id** (&str) - Required - The automation ID to filter by ### Returns `&mut Self` — Self for chaining --- ## `UIMatcher::custom_filter` Adds custom filter function. ### Parameters #### Path Parameters - **filter** (Box) - Required - The custom filter function ### Returns `&mut Self` — Self for chaining ``` -------------------------------- ### Get UI Element from Window Handle Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/api-reference/core.md Retrieves a UI element for the specified window handle. Requires a valid window handle (HWND). ```rust let automation = UIAutomation::new()?; // Assuming 'hwnd' is a valid window handle of type uiautomation::types::Handle // let element = automation.element_from_handle(hwnd)?; ``` -------------------------------- ### Create and Launch Process (No Wait) Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/api-reference/processes.md Creates and launches a process without waiting for it to become idle. The process may still be initializing after this call returns. ```rust let proc = Process::start("copy file1.txt file2.txt")?; ``` -------------------------------- ### Launch a Process Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/README.md Create a new process for an executable file. This is useful for automating the launch of applications. The `wait()` method can be used to block until the process exits. ```rust use uiautomation::processes::Process; let notepad = Process::create("notepad.exe")?; // UI automation code here notepad.wait()?; // Wait for process to close ``` -------------------------------- ### Mouse::new Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/api-reference/inputs.md Creates a new mouse input simulator. This is the entry point for mouse-related automation tasks. ```APIDOC ## Mouse::new ### Description Creates a new mouse input simulator. ### Method `new() -> Self` ### Returns `Self` - A new instance of the Mouse simulator. ``` -------------------------------- ### Use Appropriate Input Intervals for Sending Text Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/configuration.md Illustrates setting different intervals for sending text, with a shorter interval for fast systems and a longer one for slow/remote systems. ```rust // Short interval for local, fast systems element.send_text("text", 10)?; // Longer interval for slow/remote systems element.send_text("text", 100)? ``` -------------------------------- ### Simulate Keyboard Input to Root Element Source: https://github.com/leexgone/uiautomation-rs/blob/main/README.md Simulates pressing the Windows key and 'D' simultaneously to show the desktop. Requires the `UIAutomation` type. ```rust use uiautomation::core::UIAutomation; fn main() { let automation = UIAutomation::new().unwrap(); let root = automation.get_root_element().unwrap(); root.send_keys("{Win}D", 10).unwrap(); } ``` -------------------------------- ### Build UIAutomation-rs Crate Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/configuration.md Commands to build the UIAutomation-rs crate in debug, release, or with all features enabled. ```bash cargo build cargo build --release cargo build --all-features ``` -------------------------------- ### Get Control Pattern Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/api-reference/core.md Retrieves a specific control pattern interface (e.g., InvokePattern) from a UI element. This allows access to specialized functionality provided by the element. ```rust use uiautomation::patterns::InvokePattern; let invoke = element.get_pattern::()?; invoke.invoke()?; ``` -------------------------------- ### Process::start Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/api-reference/processes.md Creates and launches a process without waiting for it to become idle. The function returns immediately, allowing your program to continue while the new process initializes in the background. ```APIDOC ## Process::start ### Description Creates and launches a process immediately without waiting for it to reach an idle state. The function returns without waiting, and the process may still be initializing. ### Method `Process::start(command: S) -> Result` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust let proc = Process::start("copy file1.txt file2.txt")?; ``` ### Response #### Success Response `Result` — The successfully started process. #### Response Example None explicitly defined, but returns a `Process` struct on success. ``` -------------------------------- ### Get Control View Walker Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/api-reference/core.md Retrieves the predefined tree walker for control view, which provides a filtered view of elements. Use this for standard interaction scenarios. ```rust let automation = UIAutomation::new()?; let walker = automation.get_control_view_walker()?; ``` -------------------------------- ### Open Clipboard Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/api-reference/additional-modules.md Opens the Windows clipboard to perform read/write operations. Requires the 'clipboard' feature. ```rust use uiautomation::clipboards::Clipboard; let clipboard = Clipboard::open()?; ``` -------------------------------- ### Get Primary Screen Size Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/api-reference/inputs.md Retrieves the resolution (width and height) of the primary screen. This is useful for positioning UI elements or determining valid click coordinates. ```rust use uiautomation::inputs::get_screen_size; let (width, height) = get_screen_size()?; println!("Screen: {}x{}", width, height); ``` -------------------------------- ### Get Parent Element Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/README.md Navigate the UI tree to find the parent of a given element using the control view walker. This is essential for understanding the element hierarchy. ```rust let walker = automation.get_control_view_walker()?; let parent = walker.get_parent(&element)?; ``` -------------------------------- ### General UI Automation Control Usage Pattern Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/api-reference/controls.md Demonstrates the common pattern for finding and interacting with UI elements using control wrappers and patterns. Ensure necessary imports are included. ```rust use uiautomation::{UIAutomation, controls::{ButtonControl, CheckBoxControl}}; let automation = UIAutomation::new()?; let root = automation.get_root_element()?; // Find a button let matcher = automation.create_matcher() .from(root) .classname("Button"); if let Ok(button_elem) = matcher.find_first() { // Convert to specific control type let button: ButtonControl = button_elem.try_into()?; // Use control-specific patterns let invoke = button.get_pattern::()?; invoke.invoke()?; } ``` -------------------------------- ### Text Input with Intervals Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/api-reference/inputs.md Shows how to send text with different intervals to manage input speed and prevent data loss, especially for large amounts of text. Includes options for fast, standard, and slower systems, as well as clipboard pasting for maximum reliability. ```rust // Fast input (local app, modern systems) element.send_text("Hello", 10)?; // Standard interval (safer) element.send_text("Hello", 30)?; // Slower systems or remote sessions element.send_text("Hello", 100)?; // Clipboard paste (most reliable for long text) element.send_text_by_clipboard("Long text...")?; ``` -------------------------------- ### Retrieve Last OS Error Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/errors.md Use Error::last_os_error() to get the last error reported by the Windows operating system. This is helpful for diagnosing system-level issues. ```rust let err = Error::last_os_error(); println!("OS Error: {}", err.message()); ``` -------------------------------- ### Test UIAutomation-rs Crate Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/configuration.md Commands to run tests for the UIAutomation-rs crate, including tests with all features and documentation tests. ```bash cargo test cargo test --all-features cargo test --doc ``` -------------------------------- ### Get Process Exit Code Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/api-reference/processes.md Retrieves the exit code of a process if it has terminated. Returns `None` if the process is still running. Useful for checking the success or failure of a process. ```rust proc.wait()?; match proc.get_exit_code()? { Some(code) => println!("Exit code: {}", code), None => println!("Process still running"), } ``` -------------------------------- ### Constructing Control Wrappers from UIElement Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/api-reference/controls.md Demonstrates how to convert a generic `UIElement` into a specific control type wrapper like `ButtonControl` using `try_into()`. ```rust use uiautomation::{ UIAutomation, controls::ButtonControl }; let automation = UIAutomation::new()?; let element = automation.get_root_element()?; // Convert UIElement to specific control type let button: ButtonControl = element.try_into()?; ``` -------------------------------- ### UICacheRequest Constructor and Configuration Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/api-reference/core.md Methods for creating and configuring a UICacheRequest to optimize performance by prefetching properties and control patterns. ```APIDOC ## `UICacheRequest::from` Creates from Windows COM interface. ### Parameters #### Path Parameters - **request** (IUIAutomationCacheRequest) - Required - The Windows COM interface to create from ### Returns `Self` --- ## `UICacheRequest::add_pattern` Adds a control pattern to cache. ### Parameters #### Path Parameters - **pattern** (UIPatternType) - Required - The control pattern to add to the cache ### Returns `Result<()>` — Success indicator --- ## `UICacheRequest::add_property` Adds a property to cache. ### Parameters #### Path Parameters - **property** (UIProperty) - Required - The property to add to the cache ### Returns `Result<()>` — Success indicator ``` -------------------------------- ### Get Element Bounding Rectangle Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/README.md Retrieve the bounding rectangle of a UI element, which defines its position and size on the screen. This is useful for UI layout analysis or interaction targeting. ```rust let rect = element.get_bounding_rectangle()?; ``` -------------------------------- ### Direct Dependencies for uiautomation-rs Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/configuration.md Lists the direct dependencies required for the uiautomation-rs crate, including version specifiers and optional crates. ```toml chrono = "0.4.44" # Date/time utilities windows = "0.x" # Windows API bindings windows-core = "0.x" # Core Windows types uiautomation_derive = "0.7" # Procedural macros log = "0.4.29" (optional) # Logging trait png = "0.18.1" (optional) # PNG encoding ``` -------------------------------- ### Get UI Element Properties as Variant Source: https://github.com/leexgone/uiautomation-rs/blob/main/README.md Retrieves the Name, ControlType, and IsEnabled properties of the root UI element and prints them. Demonstrates using `UIProperty` and `Variant` types. ```rust use uiautomation::UIAutomation; use uiautomation::types::UIProperty; use uiautomation::variants::Variant; fn main() { let automation = UIAutomation::new().unwrap(); let root = automation.get_root_element().unwrap(); let name: Variant = root.get_property_value(UIProperty::Name).unwrap(); println!("name = {}", name.get_string().unwrap()); let ctrl_type: Variant = root.get_property_value(UIProperty::ControlType).unwrap(); let ctrl_type_id: i32 = ctrl_type.try_into().unwrap(); println!("control type = {}", ctrl_type_id); let enabled: Variant = root.get_property_value(UIProperty::IsEnabled).unwrap(); let enabled_str: String = enabled.try_into().unwrap(); println!("enabled = {}", enabled_str); } ``` -------------------------------- ### show_info Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/api-reference/dialogs.md Displays an informational message box with an OK button and an information icon. ```APIDOC ## show_info ### Description Displays an informational message box with an OK button and an information icon. ### Function Signature `show_info(text: &str, caption: &str)` ### Parameters - **text** (string) - Required - The informational message to display. - **caption** (string) - Required - The title of the dialog window. ### Behavior - Displays a modal dialog box. - Includes an 'OK' button. - Displays an information icon (ℹ️). ``` -------------------------------- ### Process::run Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/api-reference/processes.md Executes the configured process using the settings provided by the process builder. It handles process creation and applies any configured idle wait timeouts. ```APIDOC ## Process::run ### Description Executes the configured process. Checks if the process is already running, creates it using Windows `CreateProcessW`, applies `wait_for_idle` timeout if configured, and returns ownership of the running process. ### Method `run(&mut self) -> Result` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust let proc = Process::new("notepad.exe").run()?; ``` ### Response #### Success Response `Result` — Ownership of the running process if successful. #### Response Example None explicitly defined, but returns a `Process` struct on success. #### Error Handling - `ERR_ALREADY_RUNNING` — If the process has already been started. - Windows COM errors — If process creation fails. ``` -------------------------------- ### Find Element from Root Source: https://github.com/leexgone/uiautomation-rs/blob/main/_autodocs/README.md Search for an element starting from the root element, filtering by class name and setting a timeout. This is a common task for locating specific application windows or controls. ```rust let element = automation.create_matcher() .from(root) .classname("Notepad") .timeout(5000) .find_first()?; ```