-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlibFunc Dbg.ahk
665 lines (632 loc) · 23 KB
/
libFunc Dbg.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
#Requires AutoHotKey 2.1-alpha.4
; ————————————————————————— Debugging Functions —————————————————————————
dbgMsg(dbgMin:=0, Text:="", Title:="", Options:="") {
if (dbg >= dbgMin) {
MsgBox(Text, Title, Options)
}
}
log(dbgMin:=0, Text:="", fn:='',idTT:=0,X:=0,Y:=0) { ; print to debug, so leave unused vars as well
if (dbg >= dbgMin) {
OutputDebug(Text (idTT?idTT ': ':'') (fn?' @' fn:''))
}
}
dbgTT(dbgMin:=0, Text:="", Time:= .5,idTT:=0,X:=-1,Y:=-1) {
if (dbg >= dbgMin) {
TT(Text, Time,idTT,X,Y)
}
}
dbgTL(dbgMin:=0, Text:="", named?) { ; show tooltip and print to debug
static def := {🕐:.5, id:0, x:-1, y:-1, fn:''}
if (dbg >= dbgMin) {
Time := HasProp(named,'Time')?named.Time:(HasProp(named,'t' )?named.t :(HasProp(named,'🕐')?named.🕐:def.Time))
id := HasProp(named,'idTT')?named.idTT:(HasProp(named,'id')?named.id: def.id )
x := HasProp(named,'x' )?named.x : def.x
y := HasProp(named,'y' )?named.y : def.y
fn := HasProp(named,'fn' )?named.fn : def.fn
TT(Text,Time,id,x,y)
OutputDebug(Text (id?id ': ':'') (fn?' @' fn:''))
}
}
TT(Text:="", Time:= .5,idTT:=0,X:=-1,Y:=-1) {
static id_last := 0, id_max := 20
, timers := Map()
if idTT = 0 { ; no id given, increase by 1 to have multiple calls have different ids
(id_last>=id_max) ? id_last:=1 : id_last+=1 ; reset id over max
id := id_last
} else {
id := idTT
}
if timers.Has(id) {
SetTimer(timers.Delete(id), 0) ;, log(0,'del timer id=' id)
; } else {
; log(0,' starting timer id ' id ' idTT=' idTT)
}
MouseGetPos(&mX, &mY, &mWin, &mControl)
; mWin This optional parameter is the name of the variable in which to store the unique ID number of the window under the mouse cursor. If the window cannot be determined, this variable will be made blank.
; mControl This optional parameter is the name of the variable in which to store the name (ClassNN) of the control under the mouse cursor. If the control cannot be determined, this variable will be made blank.
stepX := 0, stepY := 50 ; offset each subsequent ToolTip # from mouse cursor
xFlag := SubStr(X, 1,1), yFlag := SubStr(Y, 1,1)
if (xFlag="o") {
stepX := SubStr(X, 2), X := -1
}
if (yFlag="o") {
stepY := SubStr(Y, 2), Y := -1
}
dbgMsg(6,"X=" X " | xFlag=" xFlag " | stepX=" stepX "`n"
"Y=" Y " | yFlag=" yFlag " | stepY=" stepY "`n"
"SubStr:" SubStr("o200", 2) )
if (X>=0
&& Y>=0) {
ToolTip(Text, X , Y ,id)
} else if (X>=0) {
ToolTip(Text, X ,mY+stepY*(id-1),id)
} else if (Y>=0) {
ToolTip(Text,mX+stepX*(id-1), Y ,id)
} else {
ToolTip(Text,mX+stepX*(id-1),mY+stepY*(id-1),id)
}
if Text != ''{
if not Time = '∞' {
SetTimer(timers[id] := %A_ThisFunc%.Bind(,,id), -Time*1000) ;, log(0,'set timer id=' id ' for f=')
}
}
}
err2str(err,f:='rme') { ; convert Error to a string (test whether a field exists before using it)
dbgtxt := ''
fields := ['Reason','Message','Extra','What']
len := fields.Length
for i, field in fields {
ch1 := SubStr(field,1,1)
if (err.HasOwnProp(field)) {
if InStr(f,ch1) {
dbgtxt .= err.%field% (i=len?'':' ¦ ')
}
}
}
return dbgtxt
}
Object2Str(Var){
Obj→Str (Var)
}
Obj→Str(Var){ ; autohotkey.com/boards/viewtopic.php?f=82&t=111713
Output := ""
if !(Type(Var) ~="Map|Array|Object|String|Number|Integer|Float"){
throw Error("Object type not supported.", -1, Format("<Object at 0x{:p}>", Type(Var)))
}
if (Type(Var)="Array"){
Output .= "["
For Index, Value in Var{
Output .= ((Index=1) ? "" : ",") Obj→Str(Value)
}
Output .= "]"
} else if (Type(Var)="Map"){
Output .= "Map("
For Key , Value in Var {
Output .= ((A_index=1) ? "" : ",") Key "," Obj→Str(Value)
}
Output .= ")"
} else if (Type(Var)="Object"){
Output .= "{"
For Key , Value in Var.Ownprops() {
Output .= ((A_index=1) ? "" : ",") Key ":" Obj→Str(Value)
}
Output .= "}"
} else if (Type(Var)="String"){
; Quotes := InStr(Var,"'") ? '"' : "'"
; MsgBox(Var "`n" Quotes )
Output := IsNumber(Var) ? Var : InStr(Var,"'") ? '"' Var '"' : "'" StrReplace(Var,"'","``'") "'"
} else {
Output := Var
}
if (Type(Var) ~="Map|Array" and ObjOwnPropCount(Var)>0){
Output .= "{"
For Key , Value in Var.Ownprops() {
Output .= ((A_index=1) ? "" : ",") Key ":" Obj→Str(Value)
}
Output .= "}"
}
Return Output
}
Str2Object(Input){
Input := Trim(Input)
Skipnext := 0
aLevel := Array()
Var :=""
if Regexmatch(Input, "i)^(\[|array\().*"){
EndArrayChar := "]"
if Regexmatch(Input, "i)^array\(.*"){
EndArrayChar := ")"
Input := RegExReplace(Input,"i)^array\((.*)", "[$1")
}
aInput := StrSplit(Input)
Output := Array()
aLevel.Push(EndArrayChar)
Loop aInput.Length {
if (A_index=1 and aInput[A_index]="["){
continue
} else if (Skipnext=1){
Skipnext := 0
} else if (aInput[A_index] ~= "``"){
Skipnext := 1
} else if (aLevel.length >1 and aLevel[aLevel.length]=aInput[A_index]){
aLevel.RemoveAt(aLevel.length)
} else if (aLevel[aLevel.length]='"' or aLevel[aLevel.length]="'"){
; skip
} else if (aInput[A_index]='"'){
aLevel.Push('"')
; continue
} else if (aInput[A_index]="'"){
aLevel.Push("'")
; continue
} else if (aInput[A_index]='{'){
aLevel.Push('}')
} else if (aInput[A_index]='['){
aLevel.Push(']')
} else if (aInput[A_index]='('){
aLevel.Push(')')
} else if (aLevel.length =1 and aInput[A_index]=","){
Output.Push(Str2Object(Var))
Var :=""
continue
} else if (aLevel.length =1 and aInput[A_index]=aLevel[aLevel.length]){
Output.Push(Str2Object(Var))
Rest := Trim(Substr(Input,A_Index+1))
if (Rest!=""){
; Hack, if an object is defined afther the array, add them as properties
Output := AddProperties(Output,Rest)
}
break
}
if (StrLen(Var)=0 and aInput[A_index]=" "){
continue
}
Var .= aInput[A_index]
}
} else if Regexmatch(Input, "i)^(map\().*"){
Output := Map()
Input := RegExReplace(Input,"i)^map\((.*)", "$1")
aInput := StrSplit(Input)
Key :=""
aLevel.Push(")")
Loop aInput.Length {
if (aLevel.length >1 and aLevel[aLevel.length]=aInput[A_index]){
aLevel.RemoveAt(aLevel.length)
} else if (Skipnext=1){
Skipnext := 0
} else if (aInput[A_index] ~= "``"){
Skipnext := 1
} else if (aLevel.length >1 and aLevel[aLevel.length]='"' or aLevel[aLevel.length]="'"){
; skip
} else if (aInput[A_index]='"'){
aLevel.Push('"')
} else if (aInput[A_index]="'"){
aLevel.Push("'")
} else if (aInput[A_index]='{'){
aLevel.Push('}')
} else if (aInput[A_index]='['){
aLevel.Push(']')
} else if (aInput[A_index]='('){
aLevel.Push(')')
} else if (aLevel.length =1 and aInput[A_index]=","){
if (Key=""){
Key := RegexReplace(Var, "`"|'")
} else {
Output[Key] := Str2Object(Var)
Key := ""
}
Var :=""
continue
} else if (aLevel.length =1 and aInput[A_index]=aLevel[aLevel.length]){
if (Key=""){
Key := RegexReplace(Var, "`"|'")
} else {
Output[Key] := Str2Object(Var)
Key := ""
}
Rest := Trim(Substr(Input,A_Index+1))
if (Rest!=""){
; Hack, if an object is defined afther the map, add them as properties
Output := AddProperties(Output,Rest)
}
break
}
if (StrLen(Var)=0 and aInput[A_index]=" "){
continue
}
Var .= aInput[A_index]
}
} else if Regexmatch(Input, "i)^({).*"){
Output := Object()
Input := RegExReplace(Input,"i)^{(.*)", "$1")
aInput := StrSplit(Input)
Key :=""
aLevel.Push("}")
Loop aInput.Length {
if (aLevel.length >1 and aLevel[aLevel.length]=aInput[A_index]){
aLevel.RemoveAt(aLevel.length)
} else if (Skipnext=1){
Skipnext := 0
} else if (aInput[A_index] ~= "``"){
Skipnext := 1
} else if (aLevel.length >1 and aLevel[aLevel.length]='"' or aLevel[aLevel.length]="'"){
; skip
} else if (aInput[A_index]='"'){
aLevel.Push('"')
} else if (aInput[A_index]="'"){
aLevel.Push("'")
} else if (aInput[A_index]='{'){
aLevel.Push('}')
} else if (aInput[A_index]='['){
aLevel.Push(']')
} else if (aInput[A_index]='('){
aLevel.Push(')')
} else if (aLevel.length =1 and aInput[A_index]=":"){
Key := Trim(Var)
Var :=""
continue
} else if (aLevel.length =1 and aInput[A_index]=","){
Output.%Key% := Str2Object(Var)
Var :=""
continue
} else if (aLevel.length =1 and aInput[A_index]=aLevel[aLevel.length]){
Output.%Key% := Str2Object(Var)
Rest := Trim(Substr(Input,A_Index+1))
if (Rest!=""){
MsgBox(Rest)
}
break
}
if (StrLen(Var)=0 and aInput[A_index]=" "){
continue
}
Var .= aInput[A_index]
}
} else{
;
Output := RegExReplace(Input, '^\"(.*)\"$' , "$1", &Count)
if (Count=0){
Output := RegExReplace(Input, "^\'(.*)\'$" , "$1", &Count)
}
OutputDebug(Output)
Output := Output
}
return Output
AddProperties(Output,PropString){
if Regexmatch(PropString, "i)^({).*"){
;Output := Object()
PropString := RegExReplace(PropString,"i)^{(.*)", "$1")
aInput := StrSplit(PropString)
Key :=""
Var := ""
aLevel := Array()
aLevel.Push("}")
Loop aInput.Length {
if (aLevel.length >1 and aLevel[aLevel.length]=aInput[A_index]){
aLevel.RemoveAt(aLevel.length)
} else if (aLevel.length >1 and aLevel[aLevel.length]='"' or aLevel[aLevel.length]="'"){
; skip
} else if (aInput[A_index]='"'){
aLevel.Push('"')
} else if (aInput[A_index]="'"){
aLevel.Push("'")
} else if (aInput[A_index]='{'){
aLevel.Push('}')
} else if (aInput[A_index]='['){
aLevel.Push(']')
} else if (aInput[A_index]='('){
aLevel.Push(')')
} else if (aLevel.length =1 and aInput[A_index]=":"){
Key := Trim(Var)
Var :=""
continue
} else if (aLevel.length =1 and aInput[A_index]=","){
Output.%Key% := Str2Object(Var)
Var :=""
continue
} else if (aLevel.length =1 and aInput[A_index]=aLevel[aLevel.length]){
Output.%Key% := Str2Object(Var)
Rest := Trim(Substr(PropString,A_Index+1))
if (Rest!=""){
MsgBox(Rest)
}
break
}
if (StrLen(Var)=0 and aInput[A_index]=" "){
continue
}
Var .= aInput[A_index]
}
}
return output
}
}
Obj_Gui(Array, ParentID := "") { ; Displays the content of the variable autohotkey.com/boards/viewtopic.php?f=83&t=103437
static ogcTreeView
if !ParentID {
myGui := Gui()
myGui.Opt("+Resize")
myGui.OnEvent("Size", Gui_Size)
myGui.MarginX := "0", myGui.MarginY := "0"
if (IsObject(Array)){
ogcTreeView := myGui.AddTreeView("w300 h300")
ogcTreeView.OnEvent("ContextMenu", ContextMenu_TreeView)
ItemID := ogcTreeView.Add("(" type(Array) ")", 0, "+Expand")
Obj_Gui(Array, ItemID)
}
else {
ogcEdit := myGui.AddEdit("w300 h200 +multi", Array)
}
myGui.Title := "Gui (" Type(Array) ")"
;Reload menu for testing
; Menus := MenuBar()
; Menus.Add("&Reload", (*) => (Reload()))
; myGui.MenuBar := Menus
myGui.Show()
return
}
if (type(Array)="Array"){
For Key, Value in Array{
if (IsObject(Value)){
ItemID := ogcTreeView.Add("[" Key "] (" type(Value) ")", ParentID, "Expand")
Obj_Gui(Value, ItemID)
}
else{
ogcTreeView.Add("[" Key "] (" type(Value) ") = " Value, ParentID, "Expand")
}
}
}
if (type(Array) = "Map") {
For Key, Value in Array {
if (IsObject(Value)) {
ItemID := ogcTreeView.Add('["' Key '"] (' type(Value) ')', ParentID, "Expand")
Obj_Gui(Value, ItemID)
} else {
ogcTreeView.Add('["' Key '"] (' type(Value) ') = ' Value, ParentID, "Expand")
}
}
aMethods := ["Count", "Capacity", "CaseSense", "Default", "__Item"]
for index, PropName in aMethods {
try ogcTreeView.Add("." PropName " (" type(Array.%PropName%) ") = " Array.%PropName%, ParentID, "Expand")
}
}
try{
For PropName, PropValue in Array.OwnProps(){
if (IsObject(PropValue)){
ItemID := ogcTreeView.Add("." PropName " (" type(PropValue) ")", ParentID, "Expand")
Obj_Gui(PropValue, ItemID)
}
else{
ogcTreeView.Add("." PropName " (" type(PropValue) ") = " PropValue, ParentID, "Expand")
}
}
}
if (type(Array) = "Func"){
aMethods := ["Name", "IsBuiltIn", "IsVariadic", "MinParams", "MaxParams"]
for index, PropName in aMethods{
ogcTreeView.Add("." PropName " (" type(Array.%PropName%) ") = " Array.%PropName%, ParentID, "Expand")
}
}
if (type(Array) = "Buffer"){
aMethods := ["Prt","Size"]
for index, PropName in aMethods{
try ogcTreeView.Add("." PropName " (" type(Array.%PropName%) ") = " Array.%PropName%, ParentID, "Expand")
}
}
if (type(Array) = "Gui"){
aMethods := ["BackColor", "FocusedControl", "Hwnd", "MarginX", "MarginY", "Name", "Title"]
for index, PropName in aMethods{
try ogcTreeView.Add("." PropName " (" type(Array.%PropName%) ") = " Array.%PropName%, ParentID, "Expand")
}
For Hwnd, oCtrl in Array{
ItemID := ogcTreeView.Add("__Enum[" Hwnd "] (" Type(oCtrl) ")", ParentID, "Expand")
Obj_Gui(oCtrl, ItemID)
}
}
if (SubStr(type(Array),1,4)="Gui."){
aMethods := ["ClassNN", "Enabled", "Focused", "Hwnd", "Name", "Text", "Type", "Value", "Visible"]
for index, PropName in aMethods {
try ogcTreeView.Add("." PropName " (" type(Array.%PropName%) ") = " Array.%PropName%, ParentID, "Expand")
}
ogcTreeView.Add(".Gui (Gui)", ParentID, "Expand")
}
return
Gui_Size(thisGui, MinMax, Width, Height) {
if MinMax = -1 ; The window has been minimized. No action needed.
return
DllCall("LockWindowUpdate", "Uint", thisGui.Hwnd)
For Hwnd, GuiCtrlObj in thisGui {
GuiCtrlObj.GetPos(&cX, &cY, &cWidth, &cHeight)
GuiCtrlObj.Move(, , Width - cX, Height -cY)
}
DllCall("LockWindowUpdate", "Uint", 0)
}
ContextMenu_TreeView(GuiCtrlObj , Item, IsRightClick, X, Y){
SelectedItemID := GuiCtrlObj.GetSelection()
RetrievedText := GuiCtrlObj.GetText(SelectedItemID)
Value := RegExReplace(RetrievedText,".*?\)\s\s=\s\s(.*)","$1")
ItemID := SelectedItemID
ParentText := ""
ParentItemID := ItemID
loop{
if (ParentItemID=0){
break
}
RetrievedParentText := GuiCtrlObj.GetText(ParentItemID)
ParentText := RegExReplace(RetrievedParentText, "(.*?)\s.*", "$1") ParentText
ParentItemID := GuiCtrlObj.GetParent(ParentItemID)
}
Menu_TV := Menu()
if(InStr(RetrievedText, ") = ")){
Menu_TV.Add("Copy [" Value "]",(*)=>(A_Clipboard:= Value, Tooltip2("Copied [" Value "]")))
Menu_TV.SetIcon("Copy [" Value "]", "Shell32.dll", 135)
}
Menu_TV.Add("Copy [" ParentText "]", (*) => (A_Clipboard := ParentText, Tooltip2("Copied [" ParentText "]")))
Menu_TV.SetIcon("Copy [" ParentText "]", "Shell32.dll", 135)
Menu_TV.Show()
}
Tooltip2(Text := "", X := "", Y := "", WhichToolTip := "") {
ToolTip(Text, X, Y, WhichToolTip)
SetTimer () => ToolTip(), -3000
}
}
EditGui(Input){
Output := Input
Gui_Edit := Gui()
Gui_Edit.Opt("+Resize")
Gui_Edit.OnEvent("Size", Gui_Size)
Gui_Edit.OnEvent("Close", Gui_Close)
Gui_Edit.MarginX := "0", Gui_Edit.MarginY := "0"
if (Type(Input)="Array") {
ogcEdit := Gui_Edit.AddListView("w300 r" Input.Length+2 " -ReadOnly -Sort -Hdr",["Edit"])
ogcEdit.OnEvent("ContextMenu", LV_ContextMenu)
for Index, Value in Input{
ogcEdit.Add(, Value)
}
ogcEdit.ModifyCol(1,300-5)
} else if (!IsObject(Input)){
ogcEdit := Gui_Edit.AddEdit("w300 h200 +multi", Input)
} else{
MsgBox("Input with type [" type(Input) "] is not yet supported.")
return Input
}
Gui_Edit.Title := "Edit Gui (" Type(Input) ")"
;Reload menu for testing
; Menus := MenuBar()
; Menus.Add("&Reload", (*) => (Reload()))
; Gui_Edit.MenuBar := Menus
Gui_Edit.Show()
HotIfWinActive "ahk_id " Gui_Edit.Hwnd
Hotkey "Delete", ClearRows
WinWaitClose(Gui_Edit)
Hotkey "Delete", "Off"
return Output
Gui_Size(thisGui, MinMax, Width, Height) {
if MinMax = -1 ; The window has been minimized. No action needed.
return
DllCall("LockWindowUpdate", "Uint", thisGui.Hwnd)
if (Type(Input) = "Array"){
ogcEdit.ModifyCol(1, Width - 5)
}
For Hwnd, GuiCtrlObj in thisGui {
GuiCtrlObj.GetPos(&cX, &cY, &cWidth, &cHeight)
GuiCtrlObj.Move(, , Width - cX, Height - cY)
}
DllCall("LockWindowUpdate", "Uint", 0)
}
Gui_Close(thisGui){
if (Type(Input) = "Array"){
Loop ogcEdit.GetCount()
{
Output[A_index] := ogcEdit.GetText(A_Index)
}
}
else{
Output := ogcEdit.text
}
}
LV_ContextMenu(LV, Item, IsRightClick, X, Y){
Rows := LV.GetCount()
Row := LV.GetNext()
ContextMenu := Menu()
ContextMenu.Add("Edit", (*) => (PostMessage(LVM_EDITLABEL := 0x1076, Row - 1, 0, , "ahk_id " LV.hwnd)))
ContextMenu.SetIcon("Edit","shell32.dll", 134)
((Rows = 0 or row=0) && ContextMenu.Disable("Edit"))
ContextMenu.Add()
ContextMenu.Add("Insert item", (*)=> (LV.Modify(, "-Select -focus"), LV.Insert(Row, "Select", ""), Output.InsertAt(Row,""),PostMessage(LVM_EDITLABEL := 0x1076, Row-1, 0, , "ahk_id " LV.hwnd)))
ContextMenu.SetIcon("Insert item", "netshell.dll", 98)
((Rows = 0 or row = 0) && ContextMenu.Disable("Insert item"))
ContextMenu.Add("Insert item below", (*)=> (Row:= LV.GetNext() + 1, LV.Modify(, "-Select -focus"),LV.Insert(Row, "Select", ""), Output.InsertAt(Row, ""),PostMessage(LVM_EDITLABEL := 0x1076, Row - 1, 0, , "ahk_id " LV.hwnd)))
ContextMenu.SetIcon("Insert item below", "comres.dll", 5)
ContextMenu.Add()
ContextMenu.Add("Delete", ClearRows)
ContextMenu.SetIcon("Delete", "Shell32.dll", 132)
((Rows = 0 or row = 0) && ContextMenu.Disable("Delete"))
ContextMenu.Show()
}
ClearRows(*) {
RowNumber := 0 ; This causes the first iteration to start the search at the top.
Loop {
RowNumber := ogcEdit.GetNext(RowNumber - 1)
if not RowNumber ; The above returned zero, so there are no more selected rows.
break
ogcEdit.Delete(RowNumber) ; Clear the row from the ListView.
Output.RemoveAt(RowNumber)
}
}
}
dbgvar(args*) { ; autohotkey.com/boards/viewtopic.php?f=83&t=123206#p547596
static LogFunc := {msg:MsgBox, tt:Tooltip, print:(x)=>FileAppend(x,"*"), dbg:OutputDebug, log:(x)=>FileAppend(x,"tmp.log")}.msg
, t := "txt"
, SerializeFunc := (t="txt") ? Obj→Str : Obj_Gui
, FormatFunc := {Terse:(info)=>Format("{1} ⟹ {2}",info.expression,info.value), Verbose:(info)=>SerializeFunc(info)}.Terse
, ReadLineFromFile := (file,lineNo)=>StrSplit(FileRead(file),"`n","`r")[lineNo]
, funcName := A_ThisFunc
, FindExpressionInLine := ((line) => RegExMatch(line, "^\s*" funcName " (.+)$", &mo) ? mo[1] : RegExMatch(line, "\b" funcName "\(((?:[^()]+|(?>\((?1)\)))+)\)", &mo) ? Substr(mo[0], StrLen(funcName) + 2, -1) : "Expression not found; line context = " line)
, Cache := Map()
try throw Error(, -1)
catch as err {
valStr := SerializeFunc(args) , args.length ? valStr := SubStr(valStr,2,-1) : 0
if not Cache.Has(fileLineKey := err.File "//" err.Line) {
Cache.Set(fileLineKey, Trim(ReadLineFromFile(err.File, err.Line)))
}
if t = "txt" {
LogFunc(FormatFunc({
expression : FindExpressionInLine(Cache[fileLineKey]),
value : valStr,
file : err.File,
lineNo : err.Line,
lineText : Cache[fileLineKey] }))
}
}
return args.length == 1 ? args[1] : args
}
dbgvar_o(args*) { ; autohotkey.com/boards/viewtopic.php?f=83&t=123206#p547596
static LogFunc := {msg:MsgBox, tt:Tooltip, print:(x)=>FileAppend(x,"*"), dbg:OutputDebug, log:(x)=>FileAppend(x,"tmp.log")}.msg
, t := "obj"
, SerializeFunc := (t="txt") ? Obj→Str : Obj_Gui
, FormatFunc := { Terse: (info) => Format("{1} ⟹ {2}", info.expression, info.value), Verbose: (info) => SerializeFunc(info) }.Terse
, ReadLineFromFile := (file, lineNo) => StrSplit(FileRead(file), "`n", "`r")[lineNo]
, funcName := A_ThisFunc
, FindExpressionInLine := ((line) => RegExMatch(line, "^\s*" funcName " (.+)$", &mo) ? mo[1] : RegExMatch(line, "\b" funcName "\(((?:[^()]+|(?>\((?1)\)))+)\)", &mo) ? Substr(mo[0], StrLen(funcName) + 2, -1) : "Expression not found; line context = " line)
, Cache := Map()
try throw Error(, -1)
catch as err {
valStr := SerializeFunc(args), args.length ? valStr := SubStr(valStr, 2, -1) : 0
if not Cache.Has(fileLineKey := err.File "//" err.Line)
Cache.Set(fileLineKey, Trim(ReadLineFromFile(err.File, err.Line)))
if t = "txt" {
LogFunc(FormatFunc({
expression : FindExpressionInLine(Cache[fileLineKey]),
value : valStr,
file : err.File,
lineNo : err.Line,
lineText : Cache[fileLineKey] }))
}
}
return args.length == 1 ? args[1] : args
}
; !3::showkeynums("'a▼⭾⇪")
showkeynums(keys) { ; show a table of keys and vk/sc codes, accepts key symbols
static K := keyConstant , vk := K._map, sc := K._mapsc ; various key name constants, gets vk code to avoid issues with another layout
, s := helperString ; K.▼ = vk['▼']
, hkf := keyFunc.customHotkeyFull
, hkSend := keyFunc.hkSend, hkSendI := keyFunc.hkSendI
k := '▼'
dbgtxt := '', dbgcount := 1
max⁄line := 1
dbgtxt .= 'key `tVK`t`tSC`t' '`n'
dbgtxt .= ' `tdec`thex`tdec`thex' '`n'
; for key in keys {
loop parse keys {
key := A_LoopField
vks := vk[key]
; k_ahk := s.key→ahk(vks)
k_ahk := GetKeyName(vks)
vk_n := GetKeyVK(k_ahk)
sc_n := GetKeySC(k_ahk)
nums := Format("`t{:3}`t{:2x} `t{:3}`t{:2x}", vk_n,vk_n, sc_n,sc_n)
dbgtxt .= key nums
dbgtxt .= (Mod(dbgcount,max⁄line)=0) ? '`n' : ' ', dbgcount += 1 ; insert a newline every max⁄line keys
}
msgbox(dbgtxt)
}