-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathUIAViewer.ahk
4343 lines (4042 loc) · 219 KB
/
UIAViewer.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#SingleInstance Force
#NoEnv
SetWorkingDir %A_ScriptDir%
SetBatchLines -1
CoordMode, Mouse, Screen
DetectHiddenWindows, On
DeepSearchFromPoint := False ; Sets the default value for the deep search checkbox. When set to True (or checked), UIAViewer iterates through the whole UIA tree to find the smallest element from mouse point. This might be very slow with large trees.
global UIA := UIA_Interface(), IsCapturing := False, Stored := {}, Acc, EnableAccTree := False, MainGuiHwnd, SaveToClipboard
Stored.TreeView := {}
DDLMacroActionValue := ""
Acc_Init()
Acc_Error(1)
_xoffsetfirst := 8
_xoffset := 5
_yoffset := 20
_ysoffset := 3
_minSplitterPosX := 100, _maxSplitterPosX := 500, _minSplitterPosY := 100, _maxSplitterPosY := 500, SplitterW = 10
Gui Main: New, AlwaysOnTop Resize hwndMainGuiHwnd, UIAViewer
Gui Main: Default
Gui, Add, Text, x310 y0 w%SplitterW% h500 vSplitter1 gMoveSplitter1
Gui, Add, Text, x%_xoffsetfirst% y390 w300 h%SplitterW% vSplitter2 gMoveSplitter2
Gui Add, GroupBox, x8 y10 w302 h130 vGBWindowInfo, Window/Control Info
Gui Add, Text, x18 y28 w30 vTextWinTitle, WinTitle:
Gui Add, Edit, x65 yp-%_ysoffset% w235 vEditWinTitle,
Gui Add, Text, x18 y56 vTextHwnd, Hwnd:
Gui Add, Edit, x65 yp-%_ysoffset% w90 vEditWinHwnd,
Gui Add, Text, x18 y86 vTextPosition, Position:
Gui Add, Edit, x65 yp-%_ysoffset% w90 vEditWinPosition,
Gui Add, Text, x18 y116 vTextSize, Size:
Gui Add, Edit, x65 yp-%_ysoffset% w90 vEditWinSize,
Gui Add, Text, x160 y56 vTextClassNN, ClassNN:
Gui Add, Edit, x210 yp-%_ysoffset% w90 vEditWinClass,
Gui Add, Text, x160 y86 vTextProcess, Process:
Gui Add, Edit, x210 yp-%_ysoffset% w90 vEditWinProcess,
Gui Add, Text, x160 y116 vTextProcessID, PID:
Gui Add, Edit, x210 yp-%_ysoffset% w90 vEditWinProcessID,
Gui Add, GroupBox, x%_xoffsetfirst% y150 w302 h240 vGBProperties, UIAutomation Element Properties
Gui Add, ListView, xm+%_xoffsetfirst% yp+%_yoffset% h210 w285 vLVPropertyIds gLVPropertyIds AltSubmit, PropertyId|Value
ClearLVPropertyIds()
Gui Add, GroupBox, x%_xoffsetfirst% y395 w302 h90 vGBPatterns, UIAutomation Element Patterns
Gui Add, TreeView, xm+%_xoffsetfirst% yp+%_yoffset% r4 w285 vTVPatterns gTVPatterns AltSubmit
Gui Add, Button, xm+10 yp+75 w150 gButCapture vButCapture, Start capturing (F1)
Gui Add, CheckBox, xp+160 yp-2 w120 vCBDeepSearch, Deep search (slower)
if DeepSearchFromPoint
GuiControl,, CBDeepSearch, 1
Gui, Add, Tab3, x320 y8 w300 h505 vTabsMain, Tree view|Macro creator
Gui, Tab, 1
Gui Add, TreeView, x+5 y+5 w200 h400 hwndhMainTreeView vMainTreeView gMainTreeView
Gui Add, Button, xp+40 y+5 w192 vButRefreshTreeView gButRefreshTreeView +Disabled, Start capturing to show tree
Gui, Tab, 2
Gui, Add, Text, x+10 y+10, Search function:
Gui, Add, DropDownList, x+10 yp-%_ysoffset% w190 vDDLMacroFunction, WaitElementExist||FindFirstBy|WaitElementNotExist|No function
Gui, Add, Text, x331 y+10, Element name:
Gui, Add, Edit, x+15 yp-%_ysoffset% w70 vEditMacroElementName, el
Gui, Add, CheckBox, x+10 yp+%_ysoffset% w100 vCBMacroCaseSensitive Checked, Case sensitive
Gui, Add, Text, x331 y+15, Match mode:
Gui, Add, DropDownList, x+25 yp-%_ysoffset% w190 vDDLMacroMatchMode, 3: Exact||2: Partial (anywhere)|1: Partial (from beginning)|RegEx
Gui, Add, Text, x331 y+15, Timeout (ms):
Gui, Add, Edit, x+23 yp-%_ysoffset% w50 Number vEditMacroTimeout, 10000
Gui, Add, Text, x+10 yp+%_ysoffset% , Action:
Gui, Add, DropDownList, x+10 yp-1 w85 gDDLMacroAction vDDLMacroAction, Click||ControlClick|Click("left")|Highlight|SetValue|Do nothing
Gui, Add, Text, x331 y+10, Start capturing and press the PrintScreen button`nto add functions.
Gui, Add, Edit, x331 y+10 w275 h350 vEditMacroContent, %A_Space%`; #Include <UIA_Interface>`n `; SetTitleMatchMode, 2
Gui, Tab
Gui, Font, Bold
Gui, Add, StatusBar, gMainSB vMainSB
SB_SetText("`tClick here to enable Acc path capturing (can't be used with UIA!)")
Gui, Font
SB_SetParts(380)
SB_SetText("`tCurrent UIA Interface version: " UIA.__Version,2)
; Change the cursor when mouse is over splitter control
OnMessage(WM_SETCURSOR := 0x20, "HandleMessage")
OnMessage(WM_MOUSEMOVE := 0x200, "HandleMessage")
Gui Show,, UIAViewer
Return
MainGuiEscape:
MainGuiClose:
IsCapturing := False
ExitApp
MainGuiSize(GuiHwnd, EventInfo, Width, Height){
global splitterW, _minSplitterPosX := 200, _maxSplitterPosX := (Width - SplitterW - 310), _minSplitterPosY := 220, _maxSplitterPosY := (Height - SplitterW - 100)
GuiControl, -Redraw, TabsMain
GuiControlGet, Pos, Pos , TabsMain
GuiControl, Move, TabsMain, % "w" Width-Posx-10 " h" Height-Posy-25
GuiControl, Move, MainTreeView, % "w" Width-Posx-25 " h" Height-Posy-85
GuiControl, Move, EditMacroContent, % "w" Width-Posx-30 " h" Height-Posy-210
GuiControl, Move, ButRefreshTreeView, % "y" Height-80 " w" Width -Posx-100
GuiControl, Move, Splitter1, % "h" Height-60
GuiControl, +Redraw, TabsMain
GuiControl, -Redraw, TVPatterns
GuiControlGet, Pos, Pos , TVPatterns
GuiControl, Move, TVPatterns, % " h" Height -Posy-60
GuiControl, Move, ButCapture, % "y" Height -50
GuiControl, Move, CBDeepSearch, % "y" Height -52
GuiControl, +Redraw, TVPatterns
GuiControlGet, Pos, Pos , GBPatterns
GuiControl, Move, GBPatterns, % " h" Height -Posy-55
GuiControl, +Redraw, MainSB
SetTimer, RedrawMainWindow, -500
}
RedrawMainWindow:
WinSet, Redraw,, ahk_id %MainGuiHwnd%
return
MainSB:
GuiControlGet, SBText,, MainSB
if (SBText == "`tClick here to enable Acc path capturing (can't be used with UIA!)") {
EnableAccTree := True
SB_SetText("",1)
SB_SetText("`tClick on path to copy to Clipboard",2)
} else if SBText {
Clipboard := SubStr(SBText, 8)
ToolTip, % "Copied """ SubStr(SBText, 8) """ to Clipboard!"
SetTimer, RemoveToolTip, -2000
}
return
LVPropertyIds:
if (A_GuiEvent == "RightClick") {
Gui, ListView, LVPropertyIds
LV_GetText(info, A_EventInfo, 2)
if info {
LV_GetText(prop, A_EventInfo, 1)
if (prop == "ControlType")
RegexMatch(info, "(?<=\().+(?=\))", info)
Clipboard := info
ToolTip, % "Copied """ info """ to Clipboard!"
SetTimer, RemoveToolTip, -2000
}
}
return
TVPatterns:
if (A_GuiEvent == "RightClick") {
Gui, TreeView, TVPatterns
TV_GetText(info, A_EventInfo)
if info {
Clipboard := info
ToolTip, % "Copied """ info """ to Clipboard!"
SetTimer, RemoveToolTip, -2000
}
}
if (A_GuiEvent == "DoubleClick") {
Gui, TreeView, TVPatterns
TV_GetText(info, A_EventInfo)
if (SubStr(info,-1) == "()") {
info := SubStr(info,1, StrLen(info)-2)
if (info == "DoDefaultAction") {
WinActivate, % "ahk_id " Stored.Hwnd
WinWaitActive, % "ahk_id " Stored.Hwnd,,1
Stored.Element.GetCurrentPatternAs("LegacyIAccessible").DoDefaultAction()
} else if (info == "Invoke") {
Stored.Element.GetCurrentPatternAs("Invoke").Invoke()
} else if (info == "Select") {
Stored.Element.GetCurrentPatternAs("SelectionItem").Select()
} else if (info == "SetValue") {
Gui +LastFound +OwnDialogs +AlwaysOnTop
InputBox, val, SetValue, Insert value to set,, 200, 120
Gui Main:+AlwaysOnTop
if (val && !ErrorLevel)
Stored.Element.GetCurrentPatternAs("Value").SetValue(val)
}
}
}
return
ButCapture:
if IsCapturing {
RangeTip()
IsCapturing := False
GuiControl, Main:, ButCapture, Start capturing (F1)
GuiControl, Main: Enable, ButCapture
GuiControl, Main: Enable, ButRefreshTreeView
GuiControl, Main:, ButRefreshTreeView, Construct tree for whole Window (F2)
} else {
IsCapturing := True
GuiControl, Main:, ButCapture, Press Esc to stop capturing
GuiControl, Main: Disable, ButCapture
GuiControl, Main: Disable, ButRefreshTreeView
GuiControl, Main:, ButRefreshTreeView, Hold cursor still to construct tree
Stored := {}
While (IsCapturing) {
MouseGetPos, mX, mY, mHwnd, mCtrl
try {
GuiControlGet, DeepSearchFromPoint,, CBDeepSearch
mEl := UIA.SmallestElementFromPoint(mX, mY, True, DeepSearchFromPoint ? UIA.ElementFromHandle(mHwnd) : "")
} catch e {
UpdateElementFields()
GuiControl, Main:, EditName, % "ERROR: " e.Message
if InStr(e.Message, "0x80070005")
GuiControl, Main:, EditValue, Try running UIAViewer with Admin privileges
}
WinGetTitle, wTitle, ahk_id %mHwnd%
WinGetPos, wX, wY, wW, wH, ahk_id %mHwnd%
WinGetClass, wClass, ahk_id %mHwnd%
WinGetText, wText, ahk_id %mHwnd%
WinGet, wProc, ProcessName, ahk_id %mHwnd%
WinGet, wProcID, PID, ahk_id %mHwnd%
GuiControl, Main:, EditWinTitle, %wTitle%
GuiControl, Main:, EditWinHwnd, ahk_id %mHwnd%
GuiControl, Main:, EditWinPosition, X: %wX% Y: %wY%
GuiControl, Main:, EditWinSize, W: %wW% H: %wH%
GuiControl, Main:, EditWinClass, %wClass%
GuiControl, Main:, EditWinProcess, %wProc%
GuiControl, Main:, EditWinProcessID, %wProcID%
if IsObject(Stored.Element) {
try {
if !UIA.CompareElements(mEl, Stored.Element) {
UpdateElementFields(mEl)
Stored.TickCount := A_TickCount
if EnableAccTree {
oAcc := Acc_ObjectFromPoint(childId, mX, mY), Acc_Location(oAcc,childId,vAccLoc)
SB_SetText(" Path: " GetAccPathTopDown(mHwnd, vAccLoc), 1)
}
} else if (Stored.TickCount && (A_TickCount - Stored.TickCount > 1000)) { ; Wait for mouse to be stable for a second
Stored.TickCount := 0
RedrawTreeView(mEl, False)
for k,v in Stored.TreeView {
if (v == mEl)
TV_Modify(k)
}
}
}
}
Stored.Hwnd := mHwnd, Stored.WinTitle := wTitle, Stored.WinClass := wClass, Stored.WinExe := wProc, Stored.Element := mEl
Sleep, 200
}
}
return
ButRefreshTreeView:
if (Stored.Hwnd && WinExist("ahk_id" Stored.Hwnd))
RedrawTreeView(UIA.ElementFromHandle(Stored.Hwnd), True)
if IsObject(Stored.Element) {
for k,v in Stored.TreeView
if UIA.CompareElements(v, Stored.Element)
TV_Modify(k)
if EnableAccTree {
br := Stored.Element.CurrentBoundingRectangle
GetAccPathTopDown(Stored.Hwnd, "x" br.l " y" br.t " w" (br.r-br.l) " h" (br.b-br.t), True)
}
}
return
MainTreeView:
if (A_GuiEvent == "S") {
UpdateElementFields(Stored.Element := Stored.Treeview[A_EventInfo])
if EnableAccTree {
br := Stored.Treeview[A_EventInfo].CurrentBoundingRectangle
SB_SetText(" Path: " GetAccPathTopDown(Stored.Hwnd, "x" br.l " y" br.t " w" (br.r-br.l) " h" (br.b-br.t)), 1)
}
}
return
DDLMacroAction:
global DDLMacroActionValue
GuiControlGet, action,, DDLMacroAction
if (action = "SetValue") {
Gui +LastFound +OwnDialogs +AlwaysOnTop
InputBox, val, SetValue, Insert value to set,, 200, 120
Gui Main:+AlwaysOnTop
if !ErrorLevel
DDLMacroActionValue := val
}
return
RemoveToolTip:
ToolTip
return
MoveSplitter1:
DragSplitter1("Splitter1")
return
MoveSplitter2:
DragSplitter2("Splitter2")
return
; Handle splitters to adjust the size of controls
GetMouseOffsets(ByRef offsetX, ByRef offsetY, _controlName) {
oldCoordMode := A_CoordModeMouse
CoordMode Mouse, Screen
MouseGetPos initScrX, initScrY, hWnd
CoordMode Mouse, Relative
MouseGetPos initWinX, initWinY
; Coordinates of the control, relative to the client area
GuiControlGet controlPos, Pos, %_controlName%
; Compute offset between click inside control and top-left corner of control
offsetX := initWinX - controlPosX, offsetY := initWinY - controlPosY
CoordMode, Mouse, %oldCoordMode% ; Restore default
}
DragSplitter1(_controlName) { ; Based on a script by user PhiLho (https://www.autohotkey.com/board/topic/8001-splitter-bar-window-control-with-ahk/)
global _minSplitterPosX, _maxSplitterPosX
if !GetKeyState("LButton")
return
GetMouseOffsets(offsetX, offsetY, _controlName)
originalSizes := GetControlSizes(_controlName, "LVPropertyIds", "GBWindowInfo", "EditWinTitle", "GBProperties", "GBPatterns", "TVPatterns", "ButCapture", "CBDeepSearch", "EditWinHwnd", "EditWinPosition", "EditWinSize", "TextClassNN", "TextProcess", "TextProcessID", "EditWinClass", "EditWinProcess", "EditWinProcessID", "MainTreeView", "ButRefreshTreeview", "Splitter2", "TabsMain", "EditMacroContent", "DDLMacroMatchMode", "DDLMacroFunction")
oldControlPos := originalSizes[_controlName]
oldCoordMode := A_CoordModeMouse
CoordMode, Mouse, Relative
Loop {
if !GetKeyState("LButton")
Break
MouseGetPos, mouseX, mouseY
moveX := Floor((mouseX-offsetX-oldControlPos.x)*(96/A_ScreenDPI))
if (oldControlPos.x+moveX > _maxSplitterPosX)
moveX := _maxSplitterPosX-oldControlPos.x
if (oldControlPos.x+moveX < _minSplitterPosX)
moveX := _minSplitterPosX-oldControlPos.x
OffsetControls(originalSizes,moveX,,,, _controlName, "CBDeepSearch")
OffsetControls(originalSizes,,, moveX,, "LVPropertyIds", "GBWindowInfo", "EditWinTitle", "GBProperties", "GBPatterns", "TVPatterns", "ButCapture", "Splitter2")
OffsetControls(originalSizes,,, moveX//2,, "EditWinHwnd", "EditWinPosition", "EditWinSize")
OffsetControls(originalSizes,moveX//2,, moveX//2,,"EditWinClass", "EditWinProcess", "EditWinProcessID")
OffsetControls(originalSizes,moveX//2,,,, "TextClassNN", "TextProcess", "TextProcessID")
OffsetControls(originalSizes,moveX,, -moveX,, "TabsMain")
OffsetControls(originalSizes,,, -moveX,, "ButRefreshTreeview", "MainTreeView", "EditMacroContent")
Sleep 100
}
CoordMode, Mouse, %oldCoordMode%
WinSet, Redraw,, ahk_id %MainGuiHwnd%
}
DragSplitter2(_controlName) {
global _minSplitterPosY, _maxSplitterPosY
if !GetKeyState("LButton")
return
GetMouseOffsets(offsetX, offsetY, _controlName)
originalSizes := GetControlSizes(_controlName, "LVPropertyIds", "GBWindowInfo", "EditWinTitle", "GBProperties", "GBPatterns", "TVPatterns", "ButCapture", "EditWinHwnd", "EditWinPosition", "EditWinSize", "TextClassNN", "TextProcess", "TextProcessID", "EditWinClass", "EditWinProcess", "EditWinProcessID", "MainTreeView", "ButRefreshTreeview")
oldControlPos := originalSizes[_controlName]
oldCoordMode := A_CoordModeMouse
CoordMode, Mouse, Relative
Loop {
if !GetKeyState("LButton")
Break
MouseGetPos, mouseX, mouseY
moveY := Floor((mouseY-offsetY-oldControlPos.y)*(96/A_ScreenDPI))
if (oldControlPos.y+moveY > _maxSplitterPosY)
moveY := _maxSplitterPosY-oldControlPos.y
if (oldControlPos.y+moveY < _minSplitterPosY)
moveY := _minSplitterPosY-oldControlPos.y
OffsetControls(originalSizes,,moveY,,, _controlName)
OffsetControls(originalSizes, ,, ,moveY, "LVPropertyIds", "GBProperties")
OffsetControls(originalSizes,,moveY, ,-moveY, "GBPatterns", "TVPatterns")
Sleep 100
}
CoordMode, Mouse, %oldCoordMode%
WinSet, Redraw,, ahk_id %MainGuiHwnd%
}
GetControlSizes(ctrls*) {
sizes := {}
for _, ctrl in ctrls {
GuiControlGet ctrlSize, Pos, %ctrl%
sizes[ctrl] := {x:ctrlSizeX, y:ctrlSizeY, w:ctrlSizeW, h:ctrlSizeH}
}
return sizes
}
OffsetControls(sizes=0, offsetX=0, offsetY=0, offsetW=0, offsetH=0, ctrls*) {
for _, ctrl in ctrls {
ctrlSize := sizes[ctrl]
GuiControl Move, %ctrl%, % (offsetX?"x" (ctrlSize.x+offsetX):"") (offsetY?" y" (ctrlSize.y+offsetY):"") (offsetW?" w" (ctrlSize.w+offsetW):"") (offsetH?" h" (ctrlSize.h+offsetH):"")
}
}
HandleMessage(p_w, p_l, p_m, p_hw)
{
global WM_SETCURSOR, WM_MOUSEMOVE
static hover, IDC_SIZEWE, h_old_cursor
if (p_m = WM_SETCURSOR) {
if hover
return, true
}
else if (p_m = WM_MOUSEMOVE) {
; cursor hovers splitter control
if InStr(A_GuiControl, "Splitter") {
if hover =
{
IDC_SIZEWE := DllCall("LoadCursor", "uint", 0, "uint", A_GuiControl == "Splitter1" ? 32644 : 32645) ; IDC_SIZEWE = 32644
hover = true
}
h_old_cursor := DllCall("SetCursor", "uint", IDC_SIZEWE)
} else if hover {
DllCall("SetCursor", "uint", h_old_cursor)
hover=
}
}
}
ClearLVPropertyIds() {
Gui, ListView, LVPropertyIds
LV_Delete()
LV_Add("", "ControlType", "")
LV_Add("", "LocalizedControlType", "")
LV_Add("", "Name", "")
LV_Add("", "Value", "")
LV_Add("", "AutomationId", "")
LV_Add("", "BoundingRectangle", "")
LV_Add("", "ClassName", "")
LV_Add("", "FullDescription", "")
LV_Add("", "HelpText", "")
LV_Add("", "AccessKey", "")
LV_Add("", "AcceleratorKey", "")
LV_Add("", "HasKeyboardFocus", "")
LV_Add("", "IsKeyboardFocusable", "")
LV_Add("", "ItemType", "")
LV_Add("", "ProcessId", "")
LV_Add("", "IsEnabled", "")
LV_Add("", "IsPassword", "")
LV_Add("", "IsOffscreen", "")
LV_Add("", "FrameworkId", "")
LV_Add("", "IsRequiredForForm", "")
LV_Add("", "ItemStatus", "")
LV_ModifyCol(1)
}
UpdateElementFields(mEl="") {
if !IsObject(mEl) {
ClearLVPropertyIds()
return
}
try {
mElPos := mEl.CurrentBoundingRectangle
RangeTip(mElPos.l, mElPos.t, mElPos.r-mElPos.l, mElPos.b-mElPos.t, "Blue", 4)
}
Gui, ListView, LVPropertyIds
LV_Delete()
Gui, TreeView, TVPatterns
TV_Delete()
try {
for k, v in UIA.PollForPotentialSupportedPatterns(mEl) {
parent := TV_Add(RegexReplace(k, "Pattern$"))
if IsObject(UIA_%k%) {
pos := 1, m := "", pattern := mEl.GetCurrentPatternAs(k)
for key, value in UIA_%k% {
if (InStr(key, "Current") && !IsObject(val := pattern[key])) {
TV_Add(SubStr(key,8) ": " val, parent)
}
}
}
if InStr(k, "Invoke")
TV_Add("Invoke()", parent)
if InStr(k, "LegacyIAccessible")
TV_Add("DoDefaultAction()", parent)
if InStr(k, "SelectionItem")
TV_Add("Select()", parent)
if InStr(k, "Value")
TV_Add("SetValue()", parent)
}
}
Gui, ListView, LVPropertyIds
try LV_Add("", "ControlType", (ctrlType := mEl.CurrentControlType) " (" UIA_Enum.UIA_ControlTypeId(ctrlType) ")")
try LV_Add("", "LocalizedControlType", mEl.CurrentLocalizedControlType)
try LV_Add("", "Name", mEl.CurrentName)
try LV_Add("", "Value", mEl.GetCurrentPropertyValue(UIA_ValueValuePropertyId := 30045))
try LV_Add("", "AutomationId", mEl.CurrentAutomationId)
try LV_Add("", "BoundingRectangle", "l: " mElPos.l " t: " mElPos.t " r: " mElPos.r " b: " mElPos.b)
try LV_Add("", "ClassName", mEl.CurrentClassName)
try LV_Add("", "FullDescription", mEl.CurrentFullDescription)
try LV_Add("", "HelpText", mEl.CurrentHelpText)
try LV_Add("", "AccessKey", mEl.CurrentAccessKey)
try LV_Add("", "AcceleratorKey", mEl.CurrentAcceleratorKey)
try LV_Add("", "HasKeyboardFocus", mEl.CurrentHasKeyboardFocus)
try LV_Add("", "IsKeyboardFocusable", mEl.CurrentIsKeyboardFocusable)
try LV_Add("", "ItemType", mEl.CurrentItemType)
try LV_Add("", "ProcessId", mEl.CurrentProcessId)
try LV_Add("", "IsEnabled", mEl.CurrentIsEnabled)
try LV_Add("", "IsPassword", mEl.CurrentIsPassword)
try LV_Add("", "IsOffscreen", mEl.CurrentIsOffscreen)
try LV_Add("", "FrameworkId", mEl.CurrentFrameworkId)
try LV_Add("", "IsRequiredForForm", mEl.CurrentIsRequiredForForm)
try LV_Add("", "ItemStatus", mEl.CurrentItemStatus)
LV_ModifyCol(1, "AutoHdr")
return
}
RedrawTreeView(el, noAncestors=True) {
global MainTreeView, hMainTreeView
Gui, TreeView, MainTreeView
TV_Delete()
TV_Add("Constructing TreeView, do not move the mouse...")
GuiControl, Main: -Redraw, MainTreeView
TV_Delete()
Stored.TreeView := {}
if noAncestors {
ConstructTreeView(el)
} else {
; Get all ancestors
ancestors := [], parent := el
while IsObject(parent) {
try {
if IsObject(parent := UIA.TreeWalkerTrue.GetParentElement(parent))
ancestors.Push(parent)
} catch {
break
}
}
; Loop backwards through ancestors to create the TreeView
maxInd := ancestors.MaxIndex()+1, parent := ""
while (--maxInd > 0) {
if !IsObject(ancestors[maxInd])
return
try {
elDesc := ancestors[maxInd].CurrentLocalizedControlType " """ ancestors[maxInd].CurrentName """"
if ((elDesc == " """"") && !ancestors[maxInd].CurrentControlType)
break
Stored.TreeView[parent := TV_Add(elDesc, parent)] := ancestors[maxInd]
}
}
; Add sibling elements
allChildren := ancestors[1].FindAll(UIA.TrueCondition, 0x2)
for _, sibling in allChildren {
if UIA.CompareElements(sibling,el)
ConstructTreeView(el, parent) ; Add child elements to TreeView also
else
try Stored.TreeView[TV_Add(sibling.CurrentLocalizedControlType " """ sibling.CurrentName """", parent)] := sibling
}
}
for k,v in Stored.TreeView
TV_Modify(k, "Expand")
SendMessage, 0x115, 6, 0,, ahk_id %hMainTreeView% ; scroll to top
GuiControl, Main: +Redraw, MainTreeView
}
ConstructTreeView(el, parent="") {
if !IsObject(el)
return
try {
elDesc := el.CurrentLocalizedControlType " """ el.CurrentName """"
;if (elDesc == " """"")
; return
Stored.TreeView[TWEl := TV_Add(elDesc, parent)] := el
if !(children := el.FindAll(UIA.TrueCondition, 0x2))
return
for k, v in children
ConstructTreeView(v, TWEl)
}
}
; Acc functions
GetAccPathTopDown(hwnd, vAccPos, updateTree=False) {
static accTree
if !IsObject(accTree)
accTree := {}
if (!IsObject(accTree[hwnd]) || updateTree)
accTree[hwnd] := BuildAccTreeRecursive(Acc_ObjectFromWindow(hwnd, 0), {})
for k, v in accTree[hwnd] {
if (v == vAccPos)
return k
}
}
BuildAccTreeRecursive(oAcc, tree, path="") {
if !IsObject(oAcc)
return tree
try
oAcc.accChildCount
catch
return tree
For i, oChild in Acc_Children(oAcc) {
if IsObject(oChild)
Acc_Location(oChild,,vChildPos)
else
Acc_Location(oAcc,oChild,vChildPos)
tree[path (path?(IsObject(oChild)?".":" c"):"") i] := vChildPos
tree := BuildAccTreeRecursive(oChild, tree, path (path?".":"") i)
}
return tree
}
Acc_Init()
{
Static h
If Not h
h:=DllCall("LoadLibrary","Str","oleacc","Ptr")
}
Acc_ObjectFromEvent(ByRef _idChild_, hWnd, idObject, idChild)
{
Acc_Init()
If DllCall("oleacc\AccessibleObjectFromEvent", "Ptr", hWnd, "UInt", idObject, "UInt", idChild, "Ptr*", pacc, "Ptr", VarSetCapacity(varChild,8+2*A_PtrSize,0)*0+&varChild)=0
Return ComObjEnwrap(9,pacc,1), _idChild_:=NumGet(varChild,8,"UInt")
}
Acc_ObjectFromPoint(ByRef _idChild_ = "", x = "", y = "")
{
Acc_Init()
If DllCall("oleacc\AccessibleObjectFromPoint", "Int64", x==""||y==""?0*DllCall("GetCursorPos","Int64*",pt)+pt:x&0xFFFFFFFF|y<<32, "Ptr*", pacc, "Ptr", VarSetCapacity(varChild,8+2*A_PtrSize,0)*0+&varChild)=0
Return ComObjEnwrap(9,pacc,1), _idChild_:=NumGet(varChild,8,"UInt")
}
Acc_ObjectFromWindow(hWnd, idObject = -4)
{
Acc_Init()
If DllCall("oleacc\AccessibleObjectFromWindow", "Ptr", hWnd, "UInt", idObject&=0xFFFFFFFF, "Ptr", -VarSetCapacity(IID,16)+NumPut(idObject==0xFFFFFFF0?0x46000000000000C0:0x719B3800AA000C81,NumPut(idObject==0xFFFFFFF0?0x0000000000020400:0x11CF3C3D618736E0,IID,"Int64"),"Int64"), "Ptr*", pacc)=0
Return ComObjEnwrap(9,pacc,1)
}
Acc_WindowFromObject(pacc)
{
If DllCall("oleacc\WindowFromAccessibleObject", "Ptr", IsObject(pacc)?ComObjValue(pacc):pacc, "Ptr*", hWnd)=0
Return hWnd
}
Acc_Error(p="") {
static setting:=0
return p=""?setting:setting:=p
}
Acc_Children(Acc) {
if ComObjType(Acc,"Name") != "IAccessible"
ErrorLevel := "Invalid IAccessible Object"
else {
Acc_Init(), cChildren:=Acc.accChildCount, Children:=[]
if DllCall("oleacc\AccessibleChildren", "Ptr",ComObjValue(Acc), "Int",0, "Int",cChildren, "Ptr",VarSetCapacity(varChildren,cChildren*(8+2*A_PtrSize),0)*0+&varChildren, "Int*",cChildren)=0 {
Loop %cChildren%
i:=(A_Index-1)*(A_PtrSize*2+8)+8, child:=NumGet(varChildren,i), Children.Push(NumGet(varChildren,i-8)=9?Acc_Query(child):child), NumGet(varChildren,i-8)=9?ObjRelease(child):
return Children.MaxIndex()?Children:
} else
ErrorLevel := "AccessibleChildren DllCall Failed"
}
if Acc_Error()
throw Exception(ErrorLevel,-1)
}
Acc_Location(Acc, ChildId=0, byref Position="") { ; adapted from Sean's code
try Acc.accLocation(ComObj(0x4003,&x:=0), ComObj(0x4003,&y:=0), ComObj(0x4003,&w:=0), ComObj(0x4003,&h:=0), ChildId)
catch
return
Position := "x" NumGet(x,0,"int") " y" NumGet(y,0,"int") " w" NumGet(w,0,"int") " h" NumGet(h,0,"int")
return {x:NumGet(x,0,"int"), y:NumGet(y,0,"int"), w:NumGet(w,0,"int"), h:NumGet(h,0,"int")}
}
Acc_Parent(Acc)
{
try parent:=Acc.accParent
return parent?Acc_Query(parent):
}
Acc_Child(Acc, ChildId=0)
{
try child:=Acc.accChild(ChildId)
return child?Acc_Query(child):
}
Acc_Query(Acc)
{
try return ComObj(9, ComObjQuery(Acc,"{618736e0-3c3d-11cf-810c-00aa00389b71}"), 1)
}
RangeTip(x:="", y:="", w:="", h:="", color:="Red", d:=2) ; from the FindText library, credit goes to feiyue
{
static id:=0
if (x="")
{
id:=0
Loop 4
Gui, Range_%A_Index%: Destroy
return
}
if (!id)
{
Loop 4
Gui, Range_%A_Index%: +Hwndid +AlwaysOnTop -Caption +ToolWindow
-DPIScale +E0x08000000
}
x:=Floor(x), y:=Floor(y), w:=Floor(w), h:=Floor(h), d:=Floor(d)
Loop 4
{
i:=A_Index
, x1:=(i=2 ? x+w : x-d)
, y1:=(i=3 ? y+h : y-d)
, w1:=(i=1 or i=3 ? w+2*d : d)
, h1:=(i=2 or i=4 ? h+2*d : d)
Gui, Range_%i%: Color, %color%
Gui, Range_%i%: Show, NA x%x1% y%y1% w%w1% h%h1%
}
}
SanitizeInput(inp) {
return StrReplace(StrReplace(inp, """", """"""), "'", "\'")
}
ReverseContent(inp) {
arr := StrSplit(inp, "`n"), len := arr.MaxIndex(), res := ""
Loop, % len
res .= arr[len-A_Index+1] "`n"
return res
}
#If !IsCapturing
~F1::ControlClick, Start capturing (F1), ahk_id %MainGuiHwnd%,,,NA
~F2::ControlClick, Construct tree for whole Window (F2), ahk_id %MainGuiHwnd%,,,NA
#If IsCapturing
Esc::gosub ButCapture
~PrintScreen::
global DDLMacroActionValue
Gui Main: Default
GuiControlGet, FocusedTab,, TabsMain
if (FocusedTab != "Macro creator")
return
if IsObject(Stored.Element) {
GuiControlGet, PreviousContent,, EditMacroContent
GuiControlGet, MacroFunction,, DDLMacroFunction
GuiControlGet, MacroMatchMode,, DDLMacroMatchMode
GuiControlGet, CaseSensitive,, CBMacroCaseSensitive
GuiControlGet, MacroElementName,, EditMacroElementName
GuiControlGet, MacroTimeout,, EditMacroTimeout
GuiControlGet, MacroAction,, DDLMacroAction
MacroContent := """ControlType=" UIA_Enum.UIA_ControlTypeId(Stored.Element.CurrentControlType) ((elName := Stored.Element.CurrentName) ? " AND Name='" SanitizeInput(elName) "'" : "") ((elAID := Stored.Element.CurrentAutomationId) ? " AND AutomationId='" SanitizeInput(elAID) "'" : "") """"
if (MacroFunction != "No function") {
RegexMatch(MacroMatchMode, "\d(?=:)", match)
MacroContent .= ",," (match ? (match=3 ? "" : match) : "RegEx") ","
MacroContent .= (CaseSensitive ? "" : "False") ","
MacroContent .= StrReplace(MacroTimeout, " ") = "10000" ? "" : MacroTimeout ","
MacroContent := MacroFunction "(" MacroContent ")"
MacroContent := RegexReplace(MacroContent, ",*\)$", ")")
if MacroElementName
MacroContent := MacroElementName "." MacroContent
if (MacroAction = "SetValue")
MacroContent .= ".Value := """ DDLMacroActionValue """"
else if (MacroAction != "Do nothing")
MacroContent .= "." MacroAction (SubStr(MacroAction, 0, 1) = ")" ? "" : "()")
}
if (Stored.WinClass != "#32768") && !(RegexMatch(ReverseContent(PreviousContent), "m`n)WinExist\(""(.*) ahk_exe (.*) ahk_class (.*)""\)$", match) && (match1 = Stored.WinTitle) && (match2 = Stored.WinExe) && (match3 = Stored.WinClass)) {
MacroContent := MacroElementName " := WinExist("""Stored.WinTitle " ahk_exe " Stored.WinExe " ahk_class " Stored.WinClass """)`n"
. "WinActivate, ahk_id %" MacroElementName "%`n"
. "WinWaitActive, ahk_id %" MacroElementName "%`n"
. MacroElementName " := UIA.ElementFromHandle(" MacroElementName ")`n`n"
. MacroContent
}
GuiControl,, EditMacroContent, % PreviousContent ? PreviousContent "`n`n" MacroContent : MacroContent
}
return
~F4::
Clipboard=
SaveToClipboard=
ToolTip, Clipboard cleared!
SetTimer, RemoveToolTip, -3000
return
; Base class for all UIA objects (UIA_Interface, UIA_Element etc), that is used to fetch properties from __Properties, and get constants and enumerations from UIA_Enum.
class UIA_Base {
__New(p="", flag=0, version="") {
ObjInsert(this,"__Type","IUIAutomation" SubStr(this.__Class,5))
,ObjInsert(this,"__Value",p)
,ObjInsert(this,"__Flag",flag)
,ObjInsert(this,"__Version",version)
}
__Get(member) {
if member not in base,__UIA,TreeWalkerTrue,TrueCondition ; base & __UIA should act as normal
{
if raw:=SubStr(member,0)="*" ; return raw data - user should know what they are doing
member:=SubStr(member,1,-1)
if RegExMatch(this.__properties, "im)^" member ",(\d+),(\w+)", m) { ; if the member is in the properties. if not - give error message
if (m2="VARIANT") ; return VARIANT data - DllCall output param different
return UIA_Hr(DllCall(this.__Vt(m1), "ptr",this.__Value, "ptr",UIA_Variant(out)))? (raw?out:UIA_VariantData(out)):
else if (m2="RECT") ; return RECT struct - DllCall output param different
return UIA_Hr(DllCall(this.__Vt(m1), "ptr",this.__Value, "ptr",&(rect,VarSetCapacity(rect,16))))? (raw?out:UIA_RectToObject(rect)):
else if (m2="double")
return UIA_Hr(DllCall(this.__Vt(m1), "ptr",this.__Value, "Double*",out))?out:
else if UIA_Hr(DllCall(this.__Vt(m1), "ptr",this.__Value, "ptr*",out))
return raw?out:m2="BSTR"?StrGet(out) (DllCall("oleaut32\SysFreeString", "ptr", out)?"":""):RegExMatch(m2,"i)IUIAutomation\K\w+",n)?(IsFunc(n)?UIA_%n%(out):new UIA_%n%(out)):out ; Bool, int, DWORD, HWND, CONTROLTYPEID, OrientationType? if IUIAutomation___ is a function, that will be called first, if not then an object is created with the name
} else if ObjHasKey(UIA_Enum, member) {
return UIA_Enum[member]
} else if RegexMatch(member, "i)PatternId|EventId|PropertyId|AttributeId|ControlTypeId|AnnotationType|StyleId|LandmarkTypeId|HeadingLevel|ChangeId|MetadataId", match) {
return UIA_Enum["UIA_" match](member)
} else throw Exception("Property not supported by the " this.__Class " Class.",-1,member)
}
}
__Set(member) {
if !(member == "base")
throw Exception("Assigning values not supported by the " this.__Class " Class.",-1,member)
}
__Call(member, params*) {
if RegexMatch(member, "i)^(?:UIA_)?(PatternId|EventId|PropertyId|AttributeId|ControlTypeId|AnnotationType|StyleId|LandmarkTypeId|HeadingLevel|ChangeId|MetadataId)$", match) {
return UIA_Enum["UIA_" match1](params*)
} else if !ObjHasKey(UIA_Base,member)&&!ObjHasKey(this,member)&&!"_NewEnum"
throw Exception("Method Call not supported by the " this.__Class " Class.",-1,member)
}
__Delete() {
this.__Flag ? ObjRelease(this.__Value):
}
__Vt(n) {
return NumGet(NumGet(this.__Value+0,"ptr")+n*A_PtrSize,"ptr")
}
}
/*
Exposes methods that enable to discover, access, and filter UI Automation elements. UI Automation exposes every element of the UI Automation as an object represented by the IUIAutomation interface. The members of this interface are not specific to a particular element.
Microsoft documentation: https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nn-uiautomationclient-iuiautomation
*/
class UIA_Interface extends UIA_Base {
static __IID := "{30cbe57d-d9d0-452a-ab13-7ac5ac4825ee}"
, __properties := "ControlViewWalker,14,IUIAutomationTreeWalker`r`nContentViewWalker,15,IUIAutomationTreeWalker`r`nRawViewWalker,16,IUIAutomationTreeWalker`r`nRawViewCondition,17,IUIAutomationCondition`r`nControlViewCondition,18,IUIAutomationCondition`r`nContentViewCondition,19,IUIAutomationCondition`r`nProxyFactoryMapping,48,IUIAutomationProxyFactoryMapping`r`nReservedNotSupportedValue,54,IUnknown`r`nReservedMixedAttributeValue,55,IUnknown"
; Compares two UI Automation elements to determine whether they represent the same underlying UI element.
CompareElements(e1,e2) {
return UIA_Hr(DllCall(this.__Vt(3), "ptr",this.__Value, "ptr",e1.__Value, "ptr",e2.__Value, "int*",out))? out:
}
; Compares two integer arrays containing run-time identifiers (IDs) to determine whether their content is the same and they belong to the same UI element. r1 and r2 need to be RuntimeId arrays (returned by GetRuntimeId()), where array.base.__Value contains the corresponding safearray.
CompareRuntimeIds(r1,r2) {
return UIA_Hr(DllCall(this.__Vt(4), "ptr",this.__Value, "ptr",ComObjValue(r1.__Value), "ptr",ComObjValue(r2.__Value), "int*",out))? out:
}
; Retrieves the UI Automation element that represents the desktop.
GetRootElement() {
return UIA_Hr(DllCall(this.__Vt(5), "ptr",this.__Value, "ptr*",out))? UIA_Element(out):
}
; Retrieves a UI Automation element for the specified window. Additionally activateChromiumAccessibility flag can be set to True to send the WM_GETOBJECT message to Chromium-based apps to activate accessibility if it isn't activated.
ElementFromHandle(hwnd, activateChromiumAccessibility=False) {
static activatedHwnds := {}
try retEl := UIA_Hr(DllCall(this.__Vt(6), "ptr",this.__Value, "ptr",hwnd, "ptr*",out))? UIA_Element(out):
if (retEl && activateChromiumAccessibility && !activatedHwnds[hwnd]) { ; In some setups Chromium-based renderers don't react to UIA calls by enabling accessibility, so we need to send the WM_GETOBJECT message to the first renderer control for the application to enable accessibility. Thanks to users malcev and rommmcek for this tip. Explanation why this works: https://www.chromium.org/developers/design-documents/accessibility/#TOC-How-Chrome-detects-the-presence-of-Assistive-Technology
WinGet, cList, ControlList, ahk_id %hwnd%
if InStr(cList, "Chrome_RenderWidgetHostHWND1") {
SendMessage, WM_GETOBJECT := 0x003D, 0, 1, Chrome_RenderWidgetHostHWND1, ahk_id %hwnd%
try rendererEl := retEl.FindFirstBy("ClassName=Chrome_RenderWidgetHostHWND"), startTime := A_TickCount
rendererEl := rendererEl ? rendererEl : retEl
if rendererEl {
rendererEl.CurrentName ; it doesn't work without calling CurrentName (at least in Skype)
while (!rendererEl.CurrentValue && (A_TickCount-startTime < 500))
Sleep, 40
}
}
activatedHwnds[hwnd] := 1
}
return UIA_Hr(DllCall(this.__Vt(6), "ptr",this.__Value, "ptr",hwnd, "ptr*",out))? UIA_Element(out):
}
; Retrieves the UI Automation element at the specified point on the desktop. Additionally activateChromiumAccessibility flag can be set to True to send the WM_GETOBJECT message to Chromium-based apps to activate accessibility if it isn't activated.
ElementFromPoint(x="", y="", activateChromiumAccessibility=False) {
static activatedHwnds := {}
if (x==""||y=="") {
VarSetCapacity(pt, 8, 0), NumPut(8, pt, "Int"), DllCall("user32.dll\GetCursorPos","UInt",&pt), x := NumGet(pt,0,"Int"), y := NumGet(pt,4,"Int")
}
if (activateChromiumAccessibility && (hwnd := DllCall("GetAncestor", "UInt", DllCall("user32.dll\WindowFromPoint", "int64", y << 32 | x), "UInt", GA_ROOT := 2)) && !activatedHwnds[hwnd]) { ; hwnd from point by SKAN
WinGet, cList, ControlList, ahk_id %hwnd%
if InStr(cList, "Chrome_RenderWidgetHostHWND1")
try this.ElementFromHandle(hwnd, False)
activatedHwnds[hwnd] := 1
}
return UIA_Hr(DllCall(this.__Vt(7), "ptr",this.__Value, "UInt64",x==""||y==""?pt:x&0xFFFFFFFF|(y&0xFFFFFFFF)<<32, "ptr*",out))? UIA_Element(out):
}
; Retrieves the UI Automation element that has the input focus.
GetFocusedElement() {
return UIA_Hr(DllCall(this.__Vt(8), "ptr",this.__Value, "ptr*",out))? UIA_Element(out):
}
; Retrieves the UI Automation element that represents the desktop, prefetches the requested properties and control patterns, and stores the prefetched items in the cache.
GetRootElementBuildCache(cacheRequest) { ; UNTESTED.
return UIA_Hr(DllCall(this.__Vt(9), "ptr",this.__Value, "ptr", cacheRequest.__Value, "ptr*",out))? UIA_Element(out):
}
; Retrieves a UI Automation element for the specified window, prefetches the requested properties and control patterns, and stores the prefetched items in the cache.
ElementFromHandleBuildCache(hwnd, cacheRequest) {
return UIA_Hr(DllCall(this.__Vt(10), "ptr",this.__Value, "ptr",hwnd, "ptr",cacheRequest.__Value, "ptr*",out))? UIA_Element(out):
}
; Retrieves the UI Automation element at the specified point on the desktop, prefetches the requested properties and control patterns, and stores the prefetched items in the cache.
ElementFromPointBuildCache(x="", y="", cacheRequest=0) { ; UNTESTED.
return UIA_Hr(DllCall(this.__Vt(11), "ptr",this.__Value, "UInt64",x==""||y==""?0*DllCall("GetCursorPos","Int64*",pt)+pt:x&0xFFFFFFFF|(y&0xFFFFFFFF)<<32, "ptr", cacheRequest.__Value, "ptr*",out))? UIA_Element(out):
}
; Retrieves the UI Automation element that has the input focus, prefetches the requested properties and control patterns, and stores the prefetched items in the cache.
GetFocusedElementBuildCache(cacheRequest) { ; UNTESTED.
return UIA_Hr(DllCall(this.__Vt(12), "ptr",this.__Value, "ptr", cacheRequest.__Value, "ptr*",out))? UIA_Element(out):
}
; Retrieves a UIA_TreeWalker object that can be used to traverse the Microsoft UI Automation tree.
CreateTreeWalker(condition) {
return UIA_Hr(DllCall(this.__Vt(13), "ptr",this.__Value, "ptr",Condition.__Value, "ptr*",out))? new UIA_TreeWalker(out):
}
CreateCacheRequest() {
return UIA_Hr(DllCall(this.__Vt(20), "ptr",this.__Value, "ptr*",out))? new UIA_CacheRequest(out):
}
; Creates a condition that is always true.
CreateTrueCondition() {
return UIA_Hr(DllCall(this.__Vt(21), "ptr",this.__Value, "ptr*",out))? new UIA_BoolCondition(out):
}
; Creates a condition that is always false.
CreateFalseCondition() {
return UIA_Hr(DllCall(this.__Vt(22), "ptr",this.__Value, "ptr*",out))? new UIA_BoolCondition(out):
}
; Creates a condition that selects elements that have a property with the specified value (var).
; If type is specified then a new variant is created with the specified variant type, otherwise the type is fetched from UIA_PropertyVariantType enums (so usually this can be left unchanged).
CreatePropertyCondition(propertyId, var, type="Variant") {
if (type!="Variant")
UIA_Variant(var,type,var)
else if (maybeVar := UIA_Enum.UIA_PropertyVariantType(propertyId)) {
UIA_Variant(var,maybeVar,var)
}
return UIA_Hr((A_PtrSize == 4) ? DllCall(this.__Vt(23), "ptr",this.__Value, "int",propertyId, "int64", NumGet(var, 0, "int64"), "int64", NumGet(var, 8, "int64"), "ptr*",out) : DllCall(this.__Vt(23), "ptr",this.__Value, "int",propertyId, "ptr",&var, "ptr*",out))? new UIA_PropertyCondition(out):
}
; Creates a condition that selects elements that have a property with the specified value (var), using optional flags. If type is specified then a new variant is created with the specified variant type, otherwise the type is fetched from UIA_PropertyVariantType enums (so usually this can be left unchanged). flags can be one of PropertyConditionFlags, default is PropertyConditionFlags_IgnoreCase = 0x1.
CreatePropertyConditionEx(propertyId, var, type="Variant", flags=0x1) {
if (type!="Variant")
UIA_Variant(var,type,var)
else if (maybeVar := UIA_Enum.UIA_PropertyVariantType(propertyId)) {
UIA_Variant(var,maybeVar,var)
}
return UIA_Hr((A_PtrSize == 4) ? DllCall(this.__Vt(24), "ptr",this.__Value, "int",propertyId, "int64", NumGet(var, 0, "int64"), "int64", NumGet(var, 8, "int64"), "uint",flags, "ptr*",out) : DllCall(this.__Vt(24), "ptr",this.__Value, "int",propertyId, "ptr",&var, "uint",flags, "ptr*",out))? new UIA_PropertyCondition(out):
}
; Creates a condition that selects elements that match both of two conditions.
CreateAndCondition(c1,c2) {
return UIA_Hr(DllCall(this.__Vt(25), "ptr",this.__Value, "ptr",c1.__Value, "ptr",c2.__Value, "ptr*",out))? new UIA_AndCondition(out):
}
; Creates a condition that selects elements based on multiple conditions, all of which must be true.
CreateAndConditionFromArray(array) {
;->in: AHK Array or Wrapped SafeArray
if ComObjValue(array)&0x2000
SafeArray:=array
else {
SafeArray:=ComObj(0x2003,DllCall("oleaut32\SafeArrayCreateVector", "uint",13, "uint",0, "uint",array.MaxIndex()),1)
for i,c in array
SafeArray[A_Index-1]:=c.__Value, ObjAddRef(c.__Value) ; AddRef - SafeArrayDestroy will release UIA_Conditions - they also release themselves
}
return UIA_Hr(DllCall(this.__Vt(26), "ptr",this.__Value, "ptr",ComObjValue(SafeArray), "ptr*",out))? new UIA_AndCondition(out):
}
; Creates a condition that selects elements from a native array, based on multiple conditions that must all be true
CreateAndConditionFromNativeArray(conditions, conditionCount) { ; UNTESTED.
/* [in] IUIAutomationCondition **conditions,
[in] int conditionCount,
[out, retval] IUIAutomationCondition **newCondition
*/
return UIA_Hr(DllCall(this.__Vt(27), "ptr",this.__Value, "ptr", conditions, "int", conditionCount, "ptr*",out))? new UIA_AndCondition(out):
}
; Creates a combination of two conditions where a match exists if either of the conditions is true.
CreateOrCondition(c1,c2) {
return UIA_Hr(DllCall(this.__Vt(28), "ptr",this.__Value, "ptr",c1.__Value, "ptr",c2.__Value, "ptr*",out))? new UIA_OrCondition(out):
}
; Creates a combination of two or more conditions where a match exists if any of the conditions is true.
CreateOrConditionFromArray(array) {
;->in: AHK Array or Wrapped SafeArray
if ComObjValue(array)&0x2000
SafeArray:=array
else {
SafeArray:=ComObj(0x2003,DllCall("oleaut32\SafeArrayCreateVector", "uint",13, "uint",0, "uint",array.MaxIndex()),1)
for i,c in array
SafeArray[A_Index-1]:=c.__Value, ObjAddRef(c.__Value) ; AddRef - SafeArrayDestroy will release UIA_Conditions - they also release themselves
}
return UIA_Hr(DllCall(this.__Vt(29), "ptr",this.__Value, "ptr",ComObjValue(SafeArray), "ptr*",out))? new UIA_OrCondition(out):
}
CreateOrConditionFromNativeArray(p*) { ; Not Implemented
return UIA_Hr(DllCall(this.__Vt(30), "ptr",this.__Value, "ptr",conditions, "int", conditionCount, "ptr*",out))? new UIA_OrCondition(out):
/* [in] IUIAutomationCondition **conditions,
[in] int conditionCount,
[out, retval] IUIAutomationCondition **newCondition
*/
}
; Creates a condition that is the negative of a specified condition.
CreateNotCondition(c) {
return UIA_Hr(DllCall(this.__Vt(31), "ptr",this.__Value, "ptr",c.__Value, "ptr*",out))? new UIA_NotCondition(out):
}
; Registers a method that handles Microsoft UI Automation events. eventId must be an EventId enum. scope must be a TreeScope enum. cacheRequest can be specified is caching is used. handler is an event handler object, which can be created with UIA_CreateEventHandler function.
AddAutomationEventHandler(eventId, element, scope=0x4, cacheRequest=0, handler="") {
return UIA_Hr(DllCall(this.__Vt(32), "ptr",this.__Value, "int", eventId, "ptr", element.__Value, "uint", scope, "ptr",cacheRequest.__Value,"ptr",handler.__Value))
}
; Removes the specified UI Automation event handler.
RemoveAutomationEventHandler(eventId, element, handler) {
return UIA_Hr(DllCall(this.__Vt(33), "ptr",this.__Value, "int", eventId, "ptr", element.__Value, "ptr",handler.__Value))
}
;~ AddPropertyChangedEventHandlerNativeArray 34
; Registers a method that handles an array of property-changed events
AddPropertyChangedEventHandler(element,scope=0x1,cacheRequest=0,handler="",propertyArray="") {
SafeArray:=ComObjArray(0x3,propertyArray.MaxIndex())
for i,propertyId in propertyArray
SafeArray[i-1]:=propertyId
return UIA_Hr(DllCall(this.__Vt(35), "ptr",this.__Value, "ptr",element.__Value, "int",scope, "ptr",cacheRequest.__Value,"ptr",handler.__Value,"ptr",ComObjValue(SafeArray)))
}
RemovePropertyChangedEventHandler(element, handler) {
return UIA_Hr(DllCall(this.__Vt(36), "ptr",this.__Value, "ptr",element.__Value, "ptr", handler.__Value))
}
AddStructureChangedEventHandler(element, handler) { ; UNTESTED.
return UIA_Hr(DllCall(this.__Vt(37), "ptr",this.__Value, "ptr",element.__Value, "ptr",handler.__Value))
}
RemoveStructureChangedEventHandler(element, handler) { ; UNTESTED