Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

The uiatomation-rs crate is a wrapper for windows uiautomation. This crate can help you make windows uiautomation API calls conveniently.

License

NotificationsYou must be signed in to change notification settings

leexgone/uiautomation-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Theuiatomation-rs crate is a wrapper for windows uiautomation. This crate can help you make windows uiautoamtion API calls conveniently.

Usages

Start by adding the dependency of this crate to your Cargo.toml file. Make use of any windows uiautomation calls as needed.

Features

Supported Features

FeatureDescriptionDefault
processSupport process operations and filter by process idFalse
dialogEnable message boxes to show messageFalse
inputSupport keyboard inputsTrue
clipboardSupport clipboard operationsFalse
patternSupport Microsoft UI Automation control patterns-
controlEnable to wrapper ui element as control to simplify operationsTrue
eventSupport Microsoft UI Automation eventsFalse
logUse log crate to print debug messageFalse
allEnable all the above featuresFalse

pattern is a feature thatcontrol depends on.

Default Features

  • input,control,pattern(introduced by thecontrol dependency)

In order to be compatible with the version beforev0.19.0, you should addprocess,dialog,event andclipboard features.

Examples

Print All UIElements

use uiautomation::Result;use uiautomation::UIAutomation;use uiautomation::UIElement;use uiautomation::UITreeWalker;fnmain(){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();}fnprint_element(walker:&UITreeWalker,element:&UIElement,level:usize) ->Result<()>{for _in0..level{print!(" ")}println!("{} - {}", element.get_classname()?, element.get_name()?);ifletOk(child) = walker.get_first_child(&element){print_element(walker,&child, level +1)?;letmut next = child;whileletOk(sibling) = walker.get_next_sibling(&next){print_element(walker,&sibling, level +1)?;            next = sibling;}}Ok(())}

Open Notepad and Input Text

use uiautomation::core::UIAutomation;use uiautomation::processes::Process;fnmain(){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");ifletOk(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();}}

Get Properties As Variant

use uiautomation::UIAutomation;use uiautomation::types::UIProperty;use uiautomation::variants::Variant;fnmain(){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);}

Simulate Keyboard Input

use uiautomation::core::UIAutomation;fnmain(){let automation =UIAutomation::new().unwrap();let root = automation.get_root_element().unwrap();    root.send_keys("{Win}D",10).unwrap();}

Add Event Handler

structMyFocusChangedEventHandler{}implCustomFocusChangedEventHandlerforMyFocusChangedEventHandler{fnhandle(&self,sender:&uiautomation::UIElement) -> uiautomation::Result<()>{println!("Focus changed: {}", sender);Ok(())}}fnmain(){let note_proc =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");ifletOk(notepad) = matcher.find_first(){let focus_changed_handler =MyFocusChangedEventHandler{};let focus_changed_handler =UIFocusChangedEventHandler::from(focus_changed_handler);        automation.add_focus_changed_event_handler(None,&focus_changed_handler).unwrap();let text_changed_handler:Box<CustomPropertyChangedEventHandlerFn> =Box::new(|sender, property, value|{println!("Property changed: {}.{:?} = {}", sender, property, value);Ok(())});let text_changed_handler =UIPropertyChangedEventHandler::from(text_changed_handler);        automation.add_property_changed_event_handler(&notepad, uiautomation::types::TreeScope::Subtree,None,&text_changed_handler,&[UIProperty::ValueValue]).unwrap();}println!("waiting for notepad.exe...");    note_proc.wait().unwrap();}

About

The uiatomation-rs crate is a wrapper for windows uiautomation. This crate can help you make windows uiautomation API calls conveniently.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors9

Languages


[8]ページ先頭

©2009-2025 Movatter.jp