uiautomation
uiautomation.uiautomation 名前空間

クラス

class  _AutomationClient
 
class  _DllClient
 
class  ControlType
 
class  PatternId
 
class  PropertyId
 
class  AccessibleRole
 
class  AccessibleState
 
class  AccessibleSelection
 
class  AnnotationType
 
class  NavigateDirection
 
class  DockPosition
 
class  ScrollAmount
 
class  StyleId
 
class  RowOrColumnMajor
 
class  ExpandCollapseState
 
class  OrientationType
 
class  ToggleState
 
class  TextPatternRangeEndpoint
 
class  TextAttributeId
 
class  TextUnit
 
class  ZoomUnit
 
class  WindowInteractionState
 
class  WindowVisualState
 
class  ConsoleColor
 
class  GAFlag
 
class  MouseEventFlag
 
class  KeyboardEventFlag
 
class  InputType
 
class  ModifierKey
 
class  SW
 
class  SWP
 
class  MB
 
class  GWL
 
class  ProcessDpiAwareness
 
class  DpiAwarenessContext
 
class  Keys
 
class  ConsoleScreenBufferInfo
 
class  MOUSEINPUT
 
class  KEYBDINPUT
 
class  HARDWAREINPUT
 
class  _INPUTUnion
 
class  INPUT
 
class  Rect
 
class  Logger
 
class  Bitmap
 
class  AnnotationPattern
 
class  CustomNavigationPattern
 
class  DockPattern
 
class  DragPattern
 
class  DropTargetPattern
 
class  ExpandCollapsePattern
 
class  GridItemPattern
 
class  GridPattern
 
class  InvokePattern
 
class  ItemContainerPattern
 
class  LegacyIAccessiblePattern
 
class  MultipleViewPattern
 
class  ObjectModelPattern
 
class  RangeValuePattern
 
class  ScrollItemPattern
 
class  ScrollPattern
 
class  SelectionItemPattern
 
class  SelectionPattern
 
class  SpreadsheetItemPattern
 
class  SpreadsheetPattern
 
class  StylesPattern
 
class  SynchronizedInputPattern
 
class  TableItemPattern
 
class  TablePattern
 
class  TextRange
 
class  TextChildPattern
 
class  TextEditPattern
 
class  TextPattern
 
class  TextPattern2
 
class  TogglePattern
 
class  TransformPattern
 
class  TransformPattern2
 
class  ValuePattern
 
class  VirtualizedItemPattern
 
class  WindowPattern
 
class  Control
 
class  AppBarControl
 
class  ButtonControl
 
class  CalendarControl
 
class  CheckBoxControl
 
class  ComboBoxControl
 
class  CustomControl
 
class  DataGridControl
 
class  DataItemControl
 
class  DocumentControl
 
class  EditControl
 
class  GroupControl
 
class  HeaderControl
 
class  HeaderItemControl
 
class  HyperlinkControl
 
class  ImageControl
 
class  ListControl
 
class  ListItemControl
 
class  MenuControl
 
class  MenuBarControl
 
class  MenuItemControl
 
class  TopLevel
 
class  PaneControl
 
class  ProgressBarControl
 
class  RadioButtonControl
 
class  ScrollBarControl
 
class  SemanticZoomControl
 
class  SeparatorControl
 
class  SliderControl
 
class  SpinnerControl
 
class  SplitButtonControl
 
class  StatusBarControl
 
class  TabControl
 
class  TabItemControl
 
class  TableControl
 
class  TextControl
 
class  ThumbControl
 
class  TitleBarControl
 
class  ToolBarControl
 
class  ToolTipControl
 
class  TreeControl
 
class  TreeItemControl
 
class  WindowControl
 
class  UIAutomationInitializerInThread
 

関数

str GetClipboardText ()
 
bool SetClipboardText (str text)
 
bool SetConsoleColor (int color)
 
bool ResetConsoleColor ()
 
int WindowFromPoint (int x, int y)
 
Tuple[int, int] GetCursorPos ()
 
bool SetCursorPos (int x, int y)
 
int GetDoubleClickTime ()
 
None mouse_event (int dwFlags, int dx, int dy, int dwData, int dwExtraInfo)
 
None keybd_event (int bVk, int bScan, int dwFlags, int dwExtraInfo)
 
bool PostMessage (int handle, int msg, int wParam, int lParam)
 
int SendMessage (int handle, int msg, int wParam, int lParam)
 
None Click (int x, int y, float waitTime=OPERATION_WAIT_TIME)
 
None MiddleClick (int x, int y, float waitTime=OPERATION_WAIT_TIME)
 
None RightClick (int x, int y, float waitTime=OPERATION_WAIT_TIME)
 
None PressMouse (int x, int y, float waitTime=OPERATION_WAIT_TIME)
 
None ReleaseMouse (float waitTime=OPERATION_WAIT_TIME)
 
None RightPressMouse (int x, int y, float waitTime=OPERATION_WAIT_TIME)
 
None RightReleaseMouse (float waitTime=OPERATION_WAIT_TIME)
 
None MiddlePressMouse (int x, int y, float waitTime=OPERATION_WAIT_TIME)
 
None MiddleReleaseMouse (float waitTime=OPERATION_WAIT_TIME)
 
None MoveTo (int x, int y, float moveSpeed=1, float waitTime=OPERATION_WAIT_TIME)
 
None DragDrop (int x1, int y1, int x2, int y2, float moveSpeed=1, float waitTime=OPERATION_WAIT_TIME)
 
None RightDragDrop (int x1, int y1, int x2, int y2, float moveSpeed=1, float waitTime=OPERATION_WAIT_TIME)
 
None MiddleDragDrop (int x1, int y1, int x2, int y2, float moveSpeed=1, float waitTime=OPERATION_WAIT_TIME)
 
None WheelDown (int wheelTimes=1, float interval=0.05, float waitTime=OPERATION_WAIT_TIME)
 
None WheelUp (int wheelTimes=1, float interval=0.05, float waitTime=OPERATION_WAIT_TIME)
 
int SetDpiAwareness (bool dpiAwarenessPerMonitor=True)
 
Tuple[int, int] GetScreenSize (bool dpiAwarenessPerMonitor=True)
 
Tuple[int, int] GetVirtualScreenSize (bool dpiAwarenessPerMonitor=True)
 
List[RectGetMonitorsRect (bool dpiAwarenessPerMonitor=False)
 
int GetPixelColor (int x, int y, int handle=0)
 
int MessageBox (str content, str title, int flags=MB.Ok)
 
bool SetForegroundWindow (int handle)
 
bool BringWindowToTop (int handle)
 
None SwitchToThisWindow (int handle)
 
int GetAncestor (int handle, int flag)
 
bool IsTopLevelWindow (int handle)
 
int GetWindowLong (int handle, int index)
 
int SetWindowLong (int handle, int index, int value)
 
bool IsIconic (int handle)
 
bool IsZoomed (int handle)
 
bool IsWindowVisible (int handle)
 
bool ShowWindow (int handle, int cmdShow)
 
bool MoveWindow (int handle, int x, int y, int width, int height, int repaint=1)
 
bool SetWindowPos (int handle, int hWndInsertAfter, int x, int y, int width, int height, int flags)
 
bool SetWindowTopmost (int handle, bool isTopmost)
 
str GetWindowText (int handle)
 
bool SetWindowText (int handle, str text)
 
str GetEditText (int handle)
 
str GetConsoleOriginalTitle ()
 
str GetConsoleTitle ()
 
bool SetConsoleTitle (str text)
 
int GetForegroundWindow ()
 
bool IsDesktopLocked ()
 
bool PlayWaveFile (str filePath=r 'C:\Windows\Media\notify.wav', bool isAsync=False, bool isLoop=False)
 
bool IsProcess64Bit (int processId)
 
bool IsUserAnAdmin ()
 
bool RunScriptAsAdmin (List[str] argv, str workingDirectory=None, int showFlag=SW.ShowNormal)
 
None SendKey (int key, float waitTime=OPERATION_WAIT_TIME)
 
None PressKey (int key, float waitTime=OPERATION_WAIT_TIME)
 
None ReleaseKey (int key, float waitTime=OPERATION_WAIT_TIME)
 
bool IsKeyPressed (int key)
 
INPUT MouseInput (int dx, int dy, int mouseData=0, int dwFlags=MouseEventFlag.LeftDown, int time_=0)
 
INPUT KeyboardInput (int wVk, int wScan, int dwFlags=KeyboardEventFlag.KeyDown, int time_=0)
 
INPUT HardwareInput (int uMsg, int param=0)
 
int SendInput (*inputs)
 
int SendUnicodeChar (str char, bool charMode=True)
 
None SendKeys (str text, float interval=0.01, float waitTime=OPERATION_WAIT_TIME, bool charMode=True, bool debug=False)
 
def GetPatternIdInterface (int patternId)
 
def CreatePattern (int patternId, ctypes.POINTER(comtypes.IUnknown) pattern)
 
None InitializeUIAutomationInCurrentThread ()
 
None UninitializeUIAutomationInCurrentThread ()
 
None SetGlobalSearchTimeout (float seconds)
 
bool WaitForExist (Control control, float timeout)
 
bool WaitForDisappear (Control control, float timeout)
 
def WalkTree (top, Callable[[TreeNode], List[TreeNode]] getChildren=None, Callable[[TreeNode], TreeNode] getFirstChild=None, Callable[[TreeNode], TreeNode] getNextSibling=None, Callable[[TreeNode, int], bool] yieldCondition=None, bool includeTop=False, int maxDepth=0xFFFFFFFF)
 
PaneControl GetRootControl ()
 
Control GetFocusedControl ()
 
Control GetForegroundControl ()
 
WindowControl GetConsoleWindow ()
 
Control ControlFromPoint (int x, int y)
 
Control ControlFromPoint2 (int x, int y)
 
Control ControlFromCursor ()
 
Control ControlFromCursor2 ()
 
Control ControlFromHandle (int handle)
 
bool ControlsAreSame (Control control1, Control control2)
 
def WalkControl (Control control, bool includeTop=False, int maxDepth=0xFFFFFFFF)
 
None LogControl (Control control, int depth=0, bool showAllName=True, bool showPid=False)
 
None EnumAndLogControl (Control control, int maxDepth=0xFFFFFFFF, bool showAllName=True, bool showPid=False, int startDepth=0)
 
None EnumAndLogControlAncestors (Control control, bool showAllName=True, bool showPid=False)
 
Control FindControl (Control control, Callable[[Control, int], bool] compare, int maxDepth=0xFFFFFFFF, bool findFromSelf=False, int foundIndex=1)
 
None ShowDesktop (float waitTime=1)
 
None WaitHotKeyReleased (Tuple[int, int] hotkey)
 
None RunByHotKey (Dict[Tuple[int, int], Callable] keyFunctions, Tuple[int, int] stopHotKey=None, Tuple[int, int] exitHotKey=(ModifierKey.Control, Keys.VK_D), bool waitHotKeyReleased=True)
 

変数

 TreeNode = Any
 
string AUTHOR_MAIL = 'yinkaisheng@live.com'
 
string METRO_WINDOW_CLASS_NAME = 'Windows.UI.Core.CoreWindow'
 
float SEARCH_INTERVAL = 0.5
 
int MAX_MOVE_SECOND = 1
 
int TIME_OUT_SECOND = 10
 
float OPERATION_WAIT_TIME = 0.5
 
int MAX_PATH = 260
 
bool DEBUG_SEARCH_TIME = False
 
bool DEBUG_EXIST_DISAPPEAR = False
 
int S_OK = 0
 
int IsNT6orHigher = 6
 
 ProcessTime = time.perf_counter
 
dictionary ControlTypeNames
 
dictionary PatternIdNames
 
dictionary PropertyIdNames
 
dictionary SpecialKeyNames
 
dictionary CharacterCodes
 
dictionary PatternConstructors
 
dictionary ControlConstructors
 
 c = ctor()
 
 notepad = WindowControl(searchDepth=1, ClassName='Notepad')
 
 lp = notepad.GetLegacyIAccessiblePattern()
 
 value = notepad.GetPropertyValue(k)
 
 children = notepad.GetChildren()
 
string hello = '{Ctrl}{End}{Enter}Hello World! 你好世界!'
 

関数詳解

◆ BringWindowToTop()

bool uiautomation.uiautomation.BringWindowToTop ( int  handle)
BringWindowToTop from Win32.
handle: int, the handle of a native window.
Return bool, True if succeed otherwise False.

◆ Click()

None uiautomation.uiautomation.Click ( int  x,
int  y,
float   waitTime = OPERATION_WAIT_TIME 
)
Simulate mouse click at point x, y.
x: int.
y: int.
waitTime: float.

◆ ControlFromCursor()

Control uiautomation.uiautomation.ControlFromCursor ( )
Call ControlFromPoint with current cursor point.
Return `Control` subclass.

◆ ControlFromCursor2()

Control uiautomation.uiautomation.ControlFromCursor2 ( )
Call ControlFromPoint2 with current cursor point.
Return `Control` subclass.

◆ ControlFromHandle()

Control uiautomation.uiautomation.ControlFromHandle ( int  handle)
Call IUIAutomation.ElementFromHandle with a native handle.
handle: int, a native window handle.
Return `Control` subclass or None.

◆ ControlFromPoint()

Control uiautomation.uiautomation.ControlFromPoint ( int  x,
int  y 
)
Call IUIAutomation ElementFromPoint x,y. May return None if mouse is over cmd's title bar icon.
Return `Control` subclass or None.

◆ ControlFromPoint2()

Control uiautomation.uiautomation.ControlFromPoint2 ( int  x,
int  y 
)
Get a native handle from point x,y and call IUIAutomation.ElementFromHandle.
Return `Control` subclass.

◆ ControlsAreSame()

bool uiautomation.uiautomation.ControlsAreSame ( Control  control1,
Control  control2 
)
control1: `Control` or its subclass.
control2: `Control` or its subclass.
Return bool, True if control1 and control2 represent the same control otherwise False.

◆ CreatePattern()

def uiautomation.uiautomation.CreatePattern ( int  patternId,
ctypes.POINTER(comtypes.IUnknown)  pattern 
)
Create a concreate pattern by pattern id and pattern(POINTER(IUnknown)).

◆ DragDrop()

None uiautomation.uiautomation.DragDrop ( int  x1,
int  y1,
int  x2,
int  y2,
float   moveSpeed = 1,
float   waitTime = OPERATION_WAIT_TIME 
)
Simulate mouse left button drag from point x1, y1 drop to point x2, y2.
x1: int.
y1: int.
x2: int.
y2: int.
moveSpeed: float, 1 normal speed, < 1 move slower, > 1 move faster.
waitTime: float.

◆ EnumAndLogControl()

None uiautomation.uiautomation.EnumAndLogControl ( Control  control,
int   maxDepth = 0xFFFFFFFF,
bool   showAllName = True,
bool   showPid = False,
int   startDepth = 0 
)
Print and log control and its descendants' propertyies.
control: `Control` or its subclass.
maxDepth: int, enum depth.
showAllName: bool, if False, print the first 30 characters of control.Name.
startDepth: int, control's current depth.

◆ EnumAndLogControlAncestors()

None uiautomation.uiautomation.EnumAndLogControlAncestors ( Control  control,
bool   showAllName = True,
bool   showPid = False 
)
Print and log control and its ancestors' propertyies.
control: `Control` or its subclass.
showAllName: bool, if False, print the first 30 characters of control.Name.

◆ FindControl()

Control uiautomation.uiautomation.FindControl ( Control  control,
Callable[[Control, int], bool]  compare,
int   maxDepth = 0xFFFFFFFF,
bool   findFromSelf = False,
int   foundIndex = 1 
)
control: `Control` or its subclass.
compare: Callable[[Control, int], bool], function(control: Control, depth: int) -> bool.
maxDepth: int, enum depth.
findFromSelf: bool, if False, do not compare self.
foundIndex: int, starts with 1, >= 1.
Return `Control` subclass or None if not find.

◆ GetAncestor()

int uiautomation.uiautomation.GetAncestor ( int  handle,
int  flag 
)
GetAncestor from Win32.
handle: int, the handle of a native window.
index: int, a value in class `GAFlag`.
Return int, a native window handle.

◆ GetClipboardText()

str uiautomation.uiautomation.GetClipboardText ( )

◆ GetConsoleOriginalTitle()

str uiautomation.uiautomation.GetConsoleOriginalTitle ( )
GetConsoleOriginalTitle from Win32.
Return str.
Only available on Windows Vista or higher.

◆ GetConsoleTitle()

str uiautomation.uiautomation.GetConsoleTitle ( )
GetConsoleTitle from Win32.
Return str.

◆ GetConsoleWindow()

WindowControl uiautomation.uiautomation.GetConsoleWindow ( )
Return `WindowControl` or None, a console window that runs python.

◆ GetCursorPos()

Tuple[int, int] uiautomation.uiautomation.GetCursorPos ( )
GetCursorPos from Win32.
Get current mouse cursor positon.
Return Tuple[int, int], two ints tuple (x, y).

◆ GetDoubleClickTime()

int uiautomation.uiautomation.GetDoubleClickTime ( )
GetDoubleClickTime from Win32.
Return int, in milliseconds.

◆ GetEditText()

str uiautomation.uiautomation.GetEditText ( int  handle)
Get text of a native Win32 Edit.
handle: int, the handle of a native window.
Return str.

◆ GetFocusedControl()

Control uiautomation.uiautomation.GetFocusedControl ( )
Return `Control` subclass.

◆ GetForegroundControl()

Control uiautomation.uiautomation.GetForegroundControl ( )
Return `Control` subclass.

◆ GetForegroundWindow()

int uiautomation.uiautomation.GetForegroundWindow ( )
GetForegroundWindow from Win32.
Return int, the native handle of the foreground window.

◆ GetMonitorsRect()

List[Rect] uiautomation.uiautomation.GetMonitorsRect ( bool   dpiAwarenessPerMonitor = False)
Get monitors' rect.
dpiAwarenessPerMonitor: bool.
Return List[Rect].

◆ GetPatternIdInterface()

def uiautomation.uiautomation.GetPatternIdInterface ( int  patternId)
Get pattern COM interface by pattern id.
patternId: int, a value in class `PatternId`.
Return comtypes._cominterface_meta.

◆ GetPixelColor()

int uiautomation.uiautomation.GetPixelColor ( int  x,
int  y,
int   handle = 0 
)
Get pixel color of a native window.
x: int.
y: int.
handle: int, the handle of a native window.
Return int, the bgr value of point (x,y).
r = bgr & 0x0000FF
g = (bgr & 0x00FF00) >> 8
b = (bgr & 0xFF0000) >> 16
If handle is 0, get pixel from Desktop window(root control).
Note:
Not all devices support GetPixel.
An application should call GetDeviceCaps to determine whether a specified device supports this function.
For example, console window doesn't support.

◆ GetRootControl()

PaneControl uiautomation.uiautomation.GetRootControl ( )
Get root control, the Desktop window.
Return `PaneControl`.

◆ GetScreenSize()

Tuple[int, int] uiautomation.uiautomation.GetScreenSize ( bool   dpiAwarenessPerMonitor = True)
dpiAwarenessPerMonitor: bool.
Return Tuple[int, int], two ints tuple (width, height).

◆ GetVirtualScreenSize()

Tuple[int, int] uiautomation.uiautomation.GetVirtualScreenSize ( bool   dpiAwarenessPerMonitor = True)
dpiAwarenessPerMonitor: bool.
Return Tuple[int, int], two ints tuple (width, height).

◆ GetWindowLong()

int uiautomation.uiautomation.GetWindowLong ( int  handle,
int  index 
)
GetWindowLong from Win32.
handle: int, the handle of a native window.
index: int.

◆ GetWindowText()

str uiautomation.uiautomation.GetWindowText ( int  handle)
GetWindowText from Win32.
handle: int, the handle of a native window.
Return str.

◆ HardwareInput()

INPUT uiautomation.uiautomation.HardwareInput ( int  uMsg,
int   param = 0 
)
Create Win32 struct `HARDWAREINPUT` for `SendInput`.

◆ InitializeUIAutomationInCurrentThread()

None uiautomation.uiautomation.InitializeUIAutomationInCurrentThread ( )
Initialize UIAutomation in a new thread.
If you want to use functionalities related to Controls and Patterns in a new thread.
You must call this function first in the new thread.
But you can't use use a Control or a Pattern created in a different thread.
So you can't create a Control or a Pattern in main thread and then pass it to a new thread and use it.

◆ IsDesktopLocked()

bool uiautomation.uiautomation.IsDesktopLocked ( )
Check if desktop is locked.
Return bool.
Desktop is locked if press Win+L, Ctrl+Alt+Del or in remote desktop mode.

◆ IsIconic()

bool uiautomation.uiautomation.IsIconic ( int  handle)
IsIconic from Win32.
Determine whether a native window is minimized.
handle: int, the handle of a native window.
Return bool.

◆ IsKeyPressed()

bool uiautomation.uiautomation.IsKeyPressed ( int  key)
key: int, a value in class `Keys`.
Return bool.

◆ IsProcess64Bit()

bool uiautomation.uiautomation.IsProcess64Bit ( int  processId)
Return True if process is 64 bit.
Return False if process is 32 bit.
Return None if unknown, maybe caused by having no acess right to the process.

◆ IsTopLevelWindow()

bool uiautomation.uiautomation.IsTopLevelWindow ( int  handle)
IsTopLevelWindow from Win32.
handle: int, the handle of a native window.
Return bool.
Only available on Windows 7 or Higher.

◆ IsUserAnAdmin()

bool uiautomation.uiautomation.IsUserAnAdmin ( )
IsUserAnAdmin from Win32.
Return bool.
Minimum supported OS: Windows XP, Windows Server 2003

◆ IsWindowVisible()

bool uiautomation.uiautomation.IsWindowVisible ( int  handle)
IsWindowVisible from Win32.
handle: int, the handle of a native window.
Return bool.

◆ IsZoomed()

bool uiautomation.uiautomation.IsZoomed ( int  handle)
IsZoomed from Win32.
Determine whether a native window is maximized.
handle: int, the handle of a native window.
Return bool.

◆ keybd_event()

None uiautomation.uiautomation.keybd_event ( int  bVk,
int  bScan,
int  dwFlags,
int  dwExtraInfo 
)
keybd_event from Win32.

◆ KeyboardInput()

INPUT uiautomation.uiautomation.KeyboardInput ( int  wVk,
int  wScan,
int   dwFlags = KeyboardEventFlag.KeyDown,
int   time_ = 0 
)
Create Win32 struct `KEYBDINPUT` for `SendInput`.

◆ LogControl()

None uiautomation.uiautomation.LogControl ( Control  control,
int   depth = 0,
bool   showAllName = True,
bool   showPid = False 
)
Print and log control's properties.
control: `Control` or its subclass.
depth: int, current depth.
showAllName: bool, if False, print the first 30 characters of control.Name.

◆ MessageBox()

int uiautomation.uiautomation.MessageBox ( str  content,
str  title,
int   flags = MB.Ok 
)
MessageBox from Win32.
content: str.
title: str.
flags: int, a value or some combined values in class `MB`.
Return int, a value in MB whose name starts with Id, such as MB.IdOk

◆ MiddleClick()

None uiautomation.uiautomation.MiddleClick ( int  x,
int  y,
float   waitTime = OPERATION_WAIT_TIME 
)
Simulate mouse middle click at point x, y.
x: int.
y: int.
waitTime: float.

◆ MiddleDragDrop()

None uiautomation.uiautomation.MiddleDragDrop ( int  x1,
int  y1,
int  x2,
int  y2,
float   moveSpeed = 1,
float   waitTime = OPERATION_WAIT_TIME 
)
Simulate mouse middle button drag from point x1, y1 drop to point x2, y2.
x1: int.
y1: int.
x2: int.
y2: int.
moveSpeed: float, 1 normal speed, < 1 move slower, > 1 move faster.
waitTime: float.

◆ MiddlePressMouse()

None uiautomation.uiautomation.MiddlePressMouse ( int  x,
int  y,
float   waitTime = OPERATION_WAIT_TIME 
)
Press middle mouse.
x: int.
y: int.
waitTime: float.

◆ MiddleReleaseMouse()

None uiautomation.uiautomation.MiddleReleaseMouse ( float   waitTime = OPERATION_WAIT_TIME)
Release middle mouse.
waitTime: float.

◆ mouse_event()

None uiautomation.uiautomation.mouse_event ( int  dwFlags,
int  dx,
int  dy,
int  dwData,
int  dwExtraInfo 
)
mouse_event from Win32.

◆ MouseInput()

INPUT uiautomation.uiautomation.MouseInput ( int  dx,
int  dy,
int   mouseData = 0,
int   dwFlags = MouseEventFlag.LeftDown,
int   time_ = 0 
)
Create Win32 struct `MOUSEINPUT` for `SendInput`.
Return `INPUT`.

◆ MoveTo()

None uiautomation.uiautomation.MoveTo ( int  x,
int  y,
float   moveSpeed = 1,
float   waitTime = OPERATION_WAIT_TIME 
)
Simulate mouse move to point x, y from current cursor.
x: int.
y: int.
moveSpeed: float, 1 normal speed, < 1 move slower, > 1 move faster.
waitTime: float.

◆ MoveWindow()

bool uiautomation.uiautomation.MoveWindow ( int  handle,
int  x,
int  y,
int  width,
int  height,
int   repaint = 1 
)
MoveWindow from Win32.
handle: int, the handle of a native window.
x: int.
y: int.
width: int.
height: int.
repaint: int, use 1 or 0.
Return bool, True if succeed otherwise False.

◆ PlayWaveFile()

bool uiautomation.uiautomation.PlayWaveFile ( str   filePath = r'C:\Windows\Media\notify.wav',
bool   isAsync = False,
bool   isLoop = False 
)
Call PlaySound from Win32.
filePath: str, if emtpy, stop playing the current sound.
isAsync: bool, if True, the sound is played asynchronously and returns immediately.
isLoop: bool, if True, the sound plays repeatedly until PlayWaveFile(None) is called again, must also set isAsync to True.
Return bool, True if succeed otherwise False.

◆ PostMessage()

bool uiautomation.uiautomation.PostMessage ( int  handle,
int  msg,
int  wParam,
int  lParam 
)
PostMessage from Win32.
Return bool, True if succeed otherwise False.

◆ PressKey()

None uiautomation.uiautomation.PressKey ( int  key,
float   waitTime = OPERATION_WAIT_TIME 
)
Simulate a key down for key.
key: int, a value in class `Keys`.
waitTime: float.

◆ PressMouse()

None uiautomation.uiautomation.PressMouse ( int  x,
int  y,
float   waitTime = OPERATION_WAIT_TIME 
)
Press left mouse.
x: int.
y: int.
waitTime: float.

◆ ReleaseKey()

None uiautomation.uiautomation.ReleaseKey ( int  key,
float   waitTime = OPERATION_WAIT_TIME 
)
Simulate a key up for key.
key: int, a value in class `Keys`.
waitTime: float.

◆ ReleaseMouse()

None uiautomation.uiautomation.ReleaseMouse ( float   waitTime = OPERATION_WAIT_TIME)
Release left mouse.
waitTime: float.

◆ ResetConsoleColor()

bool uiautomation.uiautomation.ResetConsoleColor ( )
Reset to the default text color on console window.
Return bool, True if succeed otherwise False.

◆ RightClick()

None uiautomation.uiautomation.RightClick ( int  x,
int  y,
float   waitTime = OPERATION_WAIT_TIME 
)
Simulate mouse right click at point x, y.
x: int.
y: int.
waitTime: float.

◆ RightDragDrop()

None uiautomation.uiautomation.RightDragDrop ( int  x1,
int  y1,
int  x2,
int  y2,
float   moveSpeed = 1,
float   waitTime = OPERATION_WAIT_TIME 
)
Simulate mouse right button drag from point x1, y1 drop to point x2, y2.
x1: int.
y1: int.
x2: int.
y2: int.
moveSpeed: float, 1 normal speed, < 1 move slower, > 1 move faster.
waitTime: float.

◆ RightPressMouse()

None uiautomation.uiautomation.RightPressMouse ( int  x,
int  y,
float   waitTime = OPERATION_WAIT_TIME 
)
Press right mouse.
x: int.
y: int.
waitTime: float.

◆ RightReleaseMouse()

None uiautomation.uiautomation.RightReleaseMouse ( float   waitTime = OPERATION_WAIT_TIME)
Release right mouse.
waitTime: float.

◆ RunByHotKey()

None uiautomation.uiautomation.RunByHotKey ( Dict[Tuple[int, int], Callable]  keyFunctions,
Tuple[int, int]   stopHotKey = None,
Tuple[int, int]   exitHotKey = (ModifierKey.ControlKeys.VK_D),
bool   waitHotKeyReleased = True 
)
Bind functions with hotkeys, the function will be run or stopped in another thread when the hotkey is pressed.
keyFunctions: Dict[Tuple[int, int], Callable], such as {(uiautomation.ModifierKey.Control, uiautomation.Keys.VK_1) : function}
stopHotKey: hotkey tuple
exitHotKey: hotkey tuple
waitHotKeyReleased: bool, if True, hotkey function will be triggered after the hotkey is released

def main(stopEvent):
    while True:
        if stopEvent.is_set(): # must check stopEvent.is_set() if you want to stop when stop hotkey is pressed
            break
        print(n)
        n += 1
        stopEvent.wait(1)
    print('main exit')

uiautomation.RunByHotKey({(uiautomation.ModifierKey.Control, uiautomation.Keys.VK_1) : main}
                    , (uiautomation.ModifierKey.Control | uiautomation.ModifierKey.Shift, uiautomation.Keys.VK_2))

◆ RunScriptAsAdmin()

bool uiautomation.uiautomation.RunScriptAsAdmin ( List[str]  argv,
str   workingDirectory = None,
int   showFlag = SW.ShowNormal 
)
Run a python script as administrator.
System will show a popup dialog askes you whether to elevate as administrator if UAC is enabled.
argv: List[str], a str list like sys.argv, argv[0] is the script file, argv[1:] are other arguments.
workingDirectory: str, the working directory for the script file.
showFlag: int, a value in class `SW`.
Return bool, True if succeed.

◆ SendInput()

int uiautomation.uiautomation.SendInput ( inputs)
SendInput from Win32.
input: `INPUT`.
Return int, the number of events that it successfully inserted into the keyboard or mouse input stream.
            If the function returns zero, the input was already blocked by another thread.

◆ SendKey()

None uiautomation.uiautomation.SendKey ( int  key,
float   waitTime = OPERATION_WAIT_TIME 
)
Simulate typing a key.
key: int, a value in class `Keys`.

◆ SendKeys()

None uiautomation.uiautomation.SendKeys ( str  text,
float   interval = 0.01,
float   waitTime = OPERATION_WAIT_TIME,
bool   charMode = True,
bool   debug = False 
)
Simulate typing keys on keyboard.
text: str, keys to type.
interval: float, seconds between keys.
waitTime: float.
charMode: bool, if False, the text typied is depend on the input method if a input method is on.
debug: bool, if True, print the keys.
Examples:
{Ctrl}, {Delete} ... are special keys' name in SpecialKeyNames.
SendKeys('{Ctrl}a{Delete}{Ctrl}v{Ctrl}s{Ctrl}{Shift}s{Win}e{PageDown}') #press Ctrl+a, Delete, Ctrl+v, Ctrl+s, Ctrl+Shift+s, Win+e, PageDown
SendKeys('{Ctrl}(AB)({Shift}(123))') #press Ctrl+A+B, type (, press Shift+1+2+3, type ), if () follows a hold key, hold key won't release util )
SendKeys('{Ctrl}{a 3}') #press Ctrl+a at the same time, release Ctrl+a, then type a 2 times
SendKeys('{a 3}{B 5}') #type a 3 times, type B 5 times
SendKeys('{{}Hello{}}abc {a}{b}{c} test{} 3}{!}{a} (){(}{)}') #type: {Hello}abc abc test}}}!a ()()
SendKeys('0123456789{Enter}')
SendKeys('ABCDEFGHIJKLMNOPQRSTUVWXYZ{Enter}')
SendKeys('abcdefghijklmnopqrstuvwxyz{Enter}')
SendKeys('`~!@#$%^&*()-_=+{Enter}')
SendKeys('[]{{}{}}\\|;:\'\",<.>/?{Enter}')

◆ SendMessage()

int uiautomation.uiautomation.SendMessage ( int  handle,
int  msg,
int  wParam,
int  lParam 
)
SendMessage from Win32.
Return int, the return value specifies the result of the message processing;
            it depends on the message sent.

◆ SendUnicodeChar()

int uiautomation.uiautomation.SendUnicodeChar ( str  char,
bool   charMode = True 
)
Type a single unicode char.
char: str, len(char) must equal to 1.
charMode: bool, if False, the char typied is depend on the input method if a input method is on.
Return int, the number of events that it successfully inserted into the keyboard or mouse input stream.
            If the function returns zero, the input was already blocked by another thread.

◆ SetClipboardText()

bool uiautomation.uiautomation.SetClipboardText ( str  text)
Return bool, True if succeed otherwise False.

◆ SetConsoleColor()

bool uiautomation.uiautomation.SetConsoleColor ( int  color)
Change the text color on console window.
color: int, a value in class `ConsoleColor`.
Return bool, True if succeed otherwise False.

◆ SetConsoleTitle()

bool uiautomation.uiautomation.SetConsoleTitle ( str  text)
SetConsoleTitle from Win32.
text: str.
Return bool, True if succeed otherwise False.

◆ SetCursorPos()

bool uiautomation.uiautomation.SetCursorPos ( int  x,
int  y 
)
SetCursorPos from Win32.
Set mouse cursor to point x, y.
x: int.
y: int.
Return bool, True if succeed otherwise False.

◆ SetDpiAwareness()

int uiautomation.uiautomation.SetDpiAwareness ( bool   dpiAwarenessPerMonitor = True)
Call SetThreadDpiAwarenessContext(Windows 10 version 1607+) or SetProcessDpiAwareness(Windows 8.1+).
You should call this function with True if you enable DPI scaling. uiautomation calls this function when it initializes.
dpiAwarenessPerMonitor: bool.
Return int.

◆ SetForegroundWindow()

bool uiautomation.uiautomation.SetForegroundWindow ( int  handle)
SetForegroundWindow from Win32.
handle: int, the handle of a native window.
Return bool, True if succeed otherwise False.

◆ SetGlobalSearchTimeout()

None uiautomation.uiautomation.SetGlobalSearchTimeout ( float  seconds)
seconds: float.
To make this available, you need explicitly import uiautomation:
    from uiautomation import uiautomation as auto
    auto.SetGlobalSearchTimeout(10)

◆ SetWindowLong()

int uiautomation.uiautomation.SetWindowLong ( int  handle,
int  index,
int  value 
)
SetWindowLong from Win32.
handle: int, the handle of a native window.
index: int.
value: int.
Return int, the previous value before set.

◆ SetWindowPos()

bool uiautomation.uiautomation.SetWindowPos ( int  handle,
int  hWndInsertAfter,
int  x,
int  y,
int  width,
int  height,
int  flags 
)
SetWindowPos from Win32.
handle: int, the handle of a native window.
hWndInsertAfter: int, a value whose name starts with 'HWND' in class SWP.
x: int.
y: int.
width: int.
height: int.
flags: int, values whose name starts with 'SWP' in class `SWP`.
Return bool, True if succeed otherwise False.

◆ SetWindowText()

bool uiautomation.uiautomation.SetWindowText ( int  handle,
str  text 
)
SetWindowText from Win32.
handle: int, the handle of a native window.
text: str.
Return bool, True if succeed otherwise False.

◆ SetWindowTopmost()

bool uiautomation.uiautomation.SetWindowTopmost ( int  handle,
bool  isTopmost 
)
handle: int, the handle of a native window.
isTopmost: bool
Return bool, True if succeed otherwise False.

◆ ShowDesktop()

None uiautomation.uiautomation.ShowDesktop ( float   waitTime = 1)
Show Desktop by pressing win + d

◆ ShowWindow()

bool uiautomation.uiautomation.ShowWindow ( int  handle,
int  cmdShow 
)
ShowWindow from Win32.
handle: int, the handle of a native window.
cmdShow: int, a value in clas `SW`.
Return bool, True if succeed otherwise False.

◆ SwitchToThisWindow()

None uiautomation.uiautomation.SwitchToThisWindow ( int  handle)
SwitchToThisWindow from Win32.
handle: int, the handle of a native window.

◆ UninitializeUIAutomationInCurrentThread()

None uiautomation.uiautomation.UninitializeUIAutomationInCurrentThread ( )
Uninitialize UIAutomation in a new thread after calling InitializeUIAutomationInCurrentThread.
You must call this function when the new thread exits if you have called InitializeUIAutomationInCurrentThread in the same thread.

◆ WaitForDisappear()

bool uiautomation.uiautomation.WaitForDisappear ( Control  control,
float  timeout 
)
Check if control disappears in timeout seconds.
control: `Control` or its subclass.
timeout: float.
Return bool.

◆ WaitForExist()

bool uiautomation.uiautomation.WaitForExist ( Control  control,
float  timeout 
)
Check if control exists in timeout seconds.
control: `Control` or its subclass.
timeout: float.
Return bool.

◆ WaitHotKeyReleased()

None uiautomation.uiautomation.WaitHotKeyReleased ( Tuple[int, int]  hotkey)
hotkey: Tuple[int, int], two ints tuple (modifierKey, key)

◆ WalkControl()

def uiautomation.uiautomation.WalkControl ( Control  control,
bool   includeTop = False,
int   maxDepth = 0xFFFFFFFF 
)
control: `Control` or its subclass.
includeTop: bool, if True, yield (control, 0) first.
maxDepth: int, enum depth.
Yield 2 items tuple (control: Control, depth: int).

◆ WalkTree()

def uiautomation.uiautomation.WalkTree (   top,
Callable[[TreeNode], List[TreeNode]]   getChildren = None,
Callable[[TreeNode], TreeNode]   getFirstChild = None,
Callable[[TreeNode], TreeNode]   getNextSibling = None,
Callable[[TreeNode, int], bool]   yieldCondition = None,
bool   includeTop = False,
int   maxDepth = 0xFFFFFFFF 
)
Walk a tree not using recursive algorithm.
top: a tree node.
getChildren: Callable[[TreeNode], List[TreeNode]], function(treeNode: TreeNode) -> List[TreeNode].
getNextSibling: Callable[[TreeNode], TreeNode], function(treeNode: TreeNode) -> TreeNode.
getNextSibling: Callable[[TreeNode], TreeNode], function(treeNode: TreeNode) -> TreeNode.
yieldCondition: Callable[[TreeNode, int], bool], function(treeNode: TreeNode, depth: int) -> bool.
includeTop: bool, if True yield top first.
maxDepth: int, enum depth.

If getChildren is valid, ignore getFirstChild and getNextSibling,
    yield 3 items tuple: (treeNode, depth, remain children count in current depth).
If getChildren is not valid, using getFirstChild and getNextSibling,
    yield 2 items tuple: (treeNode, depth).
If yieldCondition is not None, only yield tree nodes that yieldCondition(treeNode: TreeNode, depth: int)->bool returns True.

For example:
def GetDirChildren(dir_):
    if os.path.isdir(dir_):
        return [os.path.join(dir_, it) for it in os.listdir(dir_)]
for it, depth, leftCount in WalkTree('D:\\', getChildren= GetDirChildren):
    print(it, depth, leftCount)

◆ WheelDown()

None uiautomation.uiautomation.WheelDown ( int   wheelTimes = 1,
float   interval = 0.05,
float   waitTime = OPERATION_WAIT_TIME 
)
Simulate mouse wheel down.
wheelTimes: int.
interval: float.
waitTime: float.

◆ WheelUp()

None uiautomation.uiautomation.WheelUp ( int   wheelTimes = 1,
float   interval = 0.05,
float   waitTime = OPERATION_WAIT_TIME 
)
Simulate mouse wheel up.
wheelTimes: int.
interval: float.
waitTime: float.

◆ WindowFromPoint()

int uiautomation.uiautomation.WindowFromPoint ( int  x,
int  y 
)
WindowFromPoint from Win32.
Return int, a native window handle.

変数詳解

◆ AUTHOR_MAIL

string uiautomation.uiautomation.AUTHOR_MAIL = 'yinkaisheng@live.com'

◆ c

uiautomation.uiautomation.c = ctor()

◆ CharacterCodes

dictionary uiautomation.uiautomation.CharacterCodes

◆ children

uiautomation.uiautomation.children = notepad.GetChildren()

◆ ControlConstructors

dictionary uiautomation.uiautomation.ControlConstructors

◆ ControlTypeNames

dictionary uiautomation.uiautomation.ControlTypeNames

◆ DEBUG_EXIST_DISAPPEAR

bool uiautomation.uiautomation.DEBUG_EXIST_DISAPPEAR = False

◆ DEBUG_SEARCH_TIME

bool uiautomation.uiautomation.DEBUG_SEARCH_TIME = False

◆ hello

string uiautomation.uiautomation.hello = '{Ctrl}{End}{Enter}Hello World! 你好世界!'

◆ IsNT6orHigher

int uiautomation.uiautomation.IsNT6orHigher = 6

◆ lp

uiautomation.uiautomation.lp = notepad.GetLegacyIAccessiblePattern()

◆ MAX_MOVE_SECOND

int uiautomation.uiautomation.MAX_MOVE_SECOND = 1

◆ MAX_PATH

int uiautomation.uiautomation.MAX_PATH = 260

◆ METRO_WINDOW_CLASS_NAME

string uiautomation.uiautomation.METRO_WINDOW_CLASS_NAME = 'Windows.UI.Core.CoreWindow'

◆ notepad

uiautomation.uiautomation.notepad = WindowControl(searchDepth=1, ClassName='Notepad')

◆ OPERATION_WAIT_TIME

float uiautomation.uiautomation.OPERATION_WAIT_TIME = 0.5

◆ PatternConstructors

dictionary uiautomation.uiautomation.PatternConstructors

◆ PatternIdNames

dictionary uiautomation.uiautomation.PatternIdNames

◆ ProcessTime

uiautomation.uiautomation.ProcessTime = time.perf_counter

◆ PropertyIdNames

dictionary uiautomation.uiautomation.PropertyIdNames

◆ S_OK

int uiautomation.uiautomation.S_OK = 0

◆ SEARCH_INTERVAL

float uiautomation.uiautomation.SEARCH_INTERVAL = 0.5

◆ SpecialKeyNames

dictionary uiautomation.uiautomation.SpecialKeyNames

◆ TIME_OUT_SECOND

int uiautomation.uiautomation.TIME_OUT_SECOND = 10

◆ TreeNode

uiautomation.uiautomation.TreeNode = Any

◆ value

uiautomation.uiautomation.value = notepad.GetPropertyValue(k)