-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfast_keyboard_window_switcher.ahk
More file actions
1148 lines (1003 loc) · 31.7 KB
/
fast_keyboard_window_switcher.ahk
File metadata and controls
1148 lines (1003 loc) · 31.7 KB
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
#Requires AutoHotkey v1.1
#Include %A_ScriptDir%\config.ahk
; close script from another script by sending exit as argument
command := A_Args[1]
if (command == "exit")
{
ExitApp
} else if (command == "reload") {
Reload
}
If Not A_IsAdmin {
Run, *RunAs %A_ScriptFullPath% ; Requires v1.0.92.01+
ExitApp
}
#Include %A_ScriptDir%\includes\includes.ahk
filtersListShouldNotTrigger := new FilterLists("list_do_not_trigger.txt")
;commandList := commandFactory.create()
A := new biga()
trayControl := new TrayControl()
S := new Settings()
searchMinLength := S.searchMinLength()
thm := new TapHoldManager(S.tapTime(),500,2)
; those are the windows that you want to permanently remember, even if the application is closed
windowHistory := new WindowHistory()
filteredWindows := new WindowManager()
allWindows := new WindowManager()
allWindows.enableDebug("allWindows")
allTrayWindows := new WindowManager()
commandFactory := new CommandFactory()
commandWindows := commandFactory.create()
; this way we can keep track which window was active last
highestRunIndex := 0
;----------------------------------------------------------------------
;
; User configuration
;
autoActivateIfOnlyOne := S.autoActivateIfOnlyOne()
sortedElementsArray := Array()
guiActive := 0
; set this to yes to enable first letter match mode where the typed
; search string must match the first letter of words in the
; window title (only alphanumeric characters are taken into account)
;
; For example, the search string "ad" matches both of these titles:
;
; AutoHotkey - Documentation
; Anne's Diary
;
firstlettermatch =
selectedIndex := 1
contentType := S.contentTypeAllWindows()
lastContentType := S.contentTypeAllWindows()
forceWindowListRefresh := 0
lastActiveWindowId := 0
activeWindowId := 0
activeWindow := 0
shiftPressed := 0
if S.useVirtualDesktops() = 1
{
DetectHiddenWindows On
#Include, %A_ScriptDir%/github_modules/VD.ahk/VD.ahk
dummyFunction1() {
static dummyStatic1 := VD.init()
}
}
; List of subtsrings separated with pipe (|) characters (e.g. carpe|diem).
; Window titles containing any of the listed substrings are filtered out
; from the list of windows.
; list is loaded from file filterlist.txt
; example asticky|blackbox|app center
filtersListShouldNotDisplay := new FilterLists("filterlist.txt")
; List of shortcuts for window titles
; one shortcut per line
; example: tb|thunderbird
FileRead, shortcutslist, shortcutslist.txt
; Set this yes to update the list of windows every time the contents of the
; listbox is updated. This is usually not necessary and it is an overhead which
; slows down the update of the listbox, so this feature is disabled by default.
dynamicwindowlist =
if S.useVirtualDesktops() = 1
{
dynamicwindowlist = yes
}
; path to sound file played when the user types a substring which
; does not match any of the windows
;
; set this to blank if you don't want a sound
;
/*
nomatchsound = %windir%\Media\ding.wav
if nomatchsound <>
ifnotexist, %nomatchsound%
;m sgbox, Sound file %nomatchsound% not found. No sound will be played.
*/
;----------------------------------------------------------------------
;
; Global variables
;
; numallwin - the number of windows on the desktop
; allwinarray - array containing the titles of windows on the desktop
; dynamicwindowlist is disabled
; allwinidarray - window ids corresponding to the titles in allwinarray
; numwin - the number of windows in the listbox
; idarray - array containing window ids for the listbox items
; orig_active_id - the window ID of the originally active window
; (when the switcher is activated)
; prev_active_id - the window ID of the last window activated in the
; background (only if activateselectioninbg is enabled)
; switcher_id - the window ID of the switcher window
; filters - array of filters for filtering out titles
; from the window list
; shortcuts - array of shortcuts for filtering out titles
; from the window list
;
;----------------------------------------------------------------------
allwinDesktopIndex := Array()
allwinProcessName := Array()
if (!a_iscompiled) {
Menu, tray, icon, icon.ico,0,1
}
AutoTrim, off
/*
if filterlist <>
{
loop, parse, filterlist, |
{
filters%a_index% = %A_LoopField%
}
}
*/
shortcuts := []
amountOfShortcuts := 0
if shortcutslist <>
{
index := 0
loop, parse, shortcutslist, `n, `r
{
;d := []
;shortcuts%a_index% = %A_LoopField%
;M sgBox, %A_LoopField%
StringSplit, cArray, A_LoopField, |
val = %cArray2%
;M sgBox, %val%
; string split pipe
val = %cArray1%
shortcuts[index, 0] := val
;d.Push(1)
val = %cArray2%
shortcuts[index, 1] := val
;d.Push(2)
;M sgBox, %d%dd
;c.Push(d)
index := index + 1
}
amountOfShortcuts := index
}
_hotKeyActionInProgress := 0
checkActiveWindowInterval := 250
Sleep, 100
thm.Add(S.hotkey(), Func("mainTriggerKey"))
;forceWindowListRefresh := 1
GoSub, UpdateWindowArrays
SetTimer, CheckActiveWindow, %checkActiveWindowInterval%
;SetTimer, DebugShowGui, 1000
#Include %A_ScriptDir%\includes\inc_gui.ahk
return
DebugShowGui:
GoSub, CloseGui
SetTimer, DebugShowGui, Off
GoSub, RefreshWindowList
GoSub, UpdateGui
Sleep, 100
forceWindowListRefresh := 0
GoSub, DebugShowGui
return
CheckActiveWindow:
newWindowId := WinExist("A")
WinGetClass, className, A
if(className = "tooltips_class32") {
return
}
if(newWindowId = switcher_id) {
return
}
SetTimer, CheckActiveWindow, Off
if(activeWindowId = 0 || newWindowId != activeWindowId) {
/*
ToolTip, set new active window! %className% |||%activeWindowId%||| >%newWindowId%<
Sleep, 3000
ToolTip,
*/
setActiveWindow(newWindowId)
;GoSub, UpdateWindowArrays
}
SetTimer, CheckActiveWindow, %checkActiveWindowInterval%
return
#If S.hotkeyReload()
if(!A_IsCompiled) {
#!y::
reload
return
}
#If
SwitchBackToLastWindow:
SetTimer, CheckActiveWindow, Off
currentWindowId := WinExist("A")
if(S.saveMousePos()) {
allWindows.storeMousePosForActiveWindow(currentWindowId)
filteredWindows.storeMousePosForActiveWindow(currentWindowId)
}
Send, !{Tab}
newWindowId := WinExist("A")
while(newWindowId = currentWindowId) {
Sleep, 10
newWindowId := WinExist("A")
;T oolTip, %newWindowId% %currentWindowId%
}
Sleep, 100
currentWindowId := WinExist("A")
setActiveWindow(currentWindowId)
activeWindow.activate(S.moveMouse(), S.saveMousePos())
SetTimer, CheckActiveWindow, %checkActiveWindowInterval%
_hotKeyActionInProgress := 0
return
setActiveWindow(windowId) {
global allWindows, lastActiveWindowId, activeWindowId, activeWindow, highestRunIndex, forceWindowListRefresh
highestRunIndex := highestRunIndex + 1
lastActiveWindowId := activeWindowId
;window := allWindows.getWindowWithId(lastActiveWindowId)
;title := window.getTitle()
activeWindowId := windowId
WinGetTitle, title, ahk_id %activeWindowId%
activeWindow := allWindows.getWindowWithId(windowId)
; the title might have changed, so we need to update it
activeWindow.setTitle(title)
class_name := activeWindow.getClassName()
;T oolTip, >%activeWindowId%< title: %title% class: %class_name%
success := allWindows.increaseRunIndexForActiveWindow(windowId, highestRunIndex)
;M sgBox, Success: %success%
;if(success = 0) {
forceWindowListRefresh := 1
;}
;M sgBox, aha! %forceWindowListRefresh%
GoSub, RefreshWindowList
}
mainTriggerKey(isHold, taps, state) {
if (isHold) {
return
}
if(_hotKeyActionInProgress = 1) {
return
}
_hotKeyActionInProgress := 1
;ToolTip % "1`n" (isHold ? "HOLD" : "TAP") "`nTaps: " taps "`nState: " state
global guiActive
if(taps = 2) {
GoSub, SwitchBackToLastWindow
} else {
if(guiActive = 1) {
send, {esc}
GoSub, CloseGui
} else {
GoSub, HotkeyAction
}
}
_hotKeyActionInProgress := 0
}
/*
#If S.useVirtualDesktops() = 1
!F1::VD.goToDesktopNum(1)
!F2::VD.goToDesktopNum(2)
+F1::VD.MoveWindowToDesktopNum("A", 1)
+F2::VD.MoveWindowToDesktopNum("A", 2)
+F10::VD.TogglePinWindow("A")
#If
*/
/*
CapsLock::
SetTimer, CheckHotkey, Off
SetTimer, StartHotkeyChecking, 300
GoSub, HotkeyAction
SetTimer, StartHotkeyChecking, Off
SetTimer, CheckHotkey, Off
return
StartHotkeyChecking:
SetTimer, StartHotkeyChecking, Off
SetTimer, CheckHotkey, 10
return
CheckHotkey:
FormatTime, Time
keystate := GetKeyState("CapsLock", "P")
;T oolTip, %Time% >%keystate%<
if(keystate = "1") {
SetTimer, CheckHotkey, Off
send, {esc}
GoSub, CloseGui
}
return
*/
HotkeyAction:
WinGetTitle, title, A
shouldNotTrigger := filtersListShouldNotTrigger.shouldNotTriggerForWindow(title)
if shouldNotTrigger
{
return
}
search =
if(S.alwaysStartWithTasks()) {
if(contentType = S.contentTypeTrayIcons()) {
forceWindowListRefresh = 1
contentType := contentTypeAllWindows
}
}
WinGet, lastActiveWindowId, ID, A
GoSub, RefreshWindowList
GoSub, UpdateGui
SetTimer, InputActiveTimer, 1
return
InputActiveTimer:
if guiActive = 0
{
GoSub, CloseGui
return
}
Input, input, L1, {enter}{esc}{backspace}{up}{down}{pgup}{pgdn}{tab}{left}{right}
if ErrorLevel = EndKey:enter
{
GoSub, ActivateWindow
SetTimer, InputActiveTimer, Off
return
}
if ErrorLevel = EndKey:escape
{
GoSub, CloseGui
SetTimer, InputActiveTimer, Off
return
}
if ErrorLevel = EndKey:backspace
{
GoSub, DeleteSearchChar
return
}
if ErrorLevel = EndKey:up
{
Send, {up}
return
}
if ErrorLevel = EndKey:down
{
Send, {down}
return
}
if ErrorLevel = EndKey:pgup
{
Send, {pgup}
return
}
if ErrorLevel = EndKey:pgdn
{
Send, {pgdn}
return
}
if ErrorLevel = EndKey:tab
if completion =
return
else
input = %completion%
; invoke digit shortcuts if applicable
if S.digitShortcuts() <>
if numwin <= 10
if input in 1,2,3,4,5,6,7,8,9,0
{
if input = 0
input = 10
if numwin < %input%
{
if nomatchsound <>
SoundPlay, %nomatchsound%
return
}
;T oolTip, %input%
;GuiControl, choose, indexListView, %input%
selectedIndex = %input%
GoSub, ActivateWindow
SetTimer, InputActiveTimer, Off
return
}
; process typed character
search = %search%%input%
;T oolTip, %search%
; check if the search matches a shortcut
; iterate shortcuts
index = 0
Loop, %amountOfShortcuts%
{
cVal := % shortcuts[index, 0]
;M sgBox, %search% %cVal%
if(search = cVal)
{
search = % shortcuts[index, 1]
break
}
index := index + 1
}
GuiControl,, Edit1, %search%
GuiControl,, InputText, %search%
length := StrLen(search)
first_letter := SubStr(search, 1, 1)
if(first_letter = ":" or first_letter = ".")
{
if(contentType != S.contentTypeCommands()) {
forceWindowListRefresh := 1
}
lastContentType := contentType
contentType := S.contentTypeCommands()
GoSub, RefreshWindowList
} else if length > 1
{
if(contentType = S.contentTypeCommands()) {
contentType := lastContentType
}
GoSub, RefreshWindowList
}
return
UpdateWindowArrays:
if(shiftPressed = 1) {
return
}
if(contentType = S.contentTypeTrayIcons()) {
trayIcons := trayControl.list()
numallwin := trayControl.Length()
allTrayWindows.clear()
Loop, % numallwin {
title := trayIcons[A_Index].process
this_id := trayIcons[A_Index].hwnd
; replace pipe (|) characters in the window title,
; because Gui Add uses it for separating listbox items
StringReplace, title, title, |, -, all
if title =
continue
allTrayWindows.addNew(this_id, title, 0,0)
}
return
}
if(contentType = S.contentTypeAllWindows()) {
WinGet, id, list, , , Program Manager
Loop, %id%
{
StringTrimRight, this_id, id%a_index%, 0
WinGetTitle, title, ahk_id %this_id%
;M sgBox, %title%
hwnd := id%A_Index%
WinGetClass, className, ahk_id %this_id%
desktopNum := 0
if S.useVirtualDesktops() = 1
{
desktopNum := VD.getDesktopNumOfWindow("ahk_id" hwnd)
If (desktopNum < 0) ;-1 for invalid window, 0 for "Show on all desktops", 1 for Desktop 1
{
continue
}
if desktopNum = 2
{
;M sgBox, %title% >%desktopNum%<
;continue
}
}
; FIXME: windows with empty titles?
if title =
continue
; don't add the switcher window
if switcher_id = %this_id%
continue
; don't add titles which match any of the filters
shouldBeFiltered := filtersListShouldNotDisplay.shouldNotTriggerForWindow(title)
if shouldBeFiltered
continue
; show process name if enabled
if S.showProcessName() || S.addProcessNameToTitle()
{
procname := allWindows.getProcessName(this_id)
if S.addProcessNameToTitle()
{
title = %procname% - %title%
}
}
;M sgBox, %title% %procname%
allWindows.addIfNotExists(this_id, title, procname, desktopNum, "", 1, className)
}
/*
DetectHiddenWindows, On
WinGet, List, List, ahk_class AutoHotkey
Loop % List {
ahkID := List%A_Index%
if allWindows.windowWithIdExists(ahkID)
continue
WinGetTitle, title, % "ahk_id" ahkID
title := RegExReplace(title, " - AutoHotkey v[\.0-9]+$")
splitPath := StrSplit(title, "\")
fileNameWithExt := splitPath[splitPath.MaxIndex()]
dotPos := InStr(fileNameWithExt, ".",, 0)
title := SubStr(fileNameWithExt, 1, dotPos-1)
procname := allWindows.getProcessName(ahkID)
;M sgBox, %title%
if S.addProcessNameToTitle()
{
title = %title% (%procname%)
}
allWindows.addIfNotExists(ahkID, title, procname, desktopNum)
}
DetectHiddenWindows, Off
*/
numallwin := allWindows.length()
}
return
RefreshWindowList:
if(shiftPressed = 1) {
return
}
; refresh the list of windows if necessary
filteredWindows.clear()
if (dynamicwindowlist = "yes" or numallwin = 0 or forceWindowListRefresh = 1)
{
;M sgBox, do it
forceWindowListRefresh := 0
GoSub, UpdateWindowArrays
}
;M sgBox, |%search%|
allWindowsAndHistory := new WindowManager()
allWindowsAndHistory.enableDebug("allWindowsAndHistory")
if(contentType = S.contentTypeTrayIcons()) {
allWindowsAndHistory.addArray(allTrayWindows.getArray())
allWindowsAndHistory.sort()
} else if(contentType = S.contentTypeCommands()) {
allWindowsAndHistory.addArray(commandWindows.getArray())
;allWindowsAndHistory.sort()
} else {
allWindows.removeNonExistent()
amountAllWindows := allWindows.length()
allWindowsAndHistory.addArray(allWindows.getArray())
;allWindowsAndHistory.sort()
amount := allWindowsAndHistory.length()
;windowHistory.sort()
allWindowsAndHistory.addUniqueArrayAtTheBottom(windowHistory.getArray())
;allWindowsAndHistory.sort()
}
amountAllWindowsAndHistory := allWindowsAndHistory.length()
minLength := searchMinLength
if(contentType = S.contentTypeCommands()) {
minLength := 3
}
typedLength := StrLen(search)
/*
if(amount < 3) {
ToolTip, no windows?
Sleep, 1000,
ToolTip,
}
*/
Loop, %amountAllWindowsAndHistory%
{
window := allWindowsAndHistory.get(A_Index)
title := window.getTitle()
if(typedLength >= minLength) {
searchString := search
if(contentType = S.contentTypeCommands()) {
;remove the : at the start
;M sgBox, %title%
searchString := SubStr(search, 2)
;T oolTip, ---%searchString%---
}
if searchString <>
if firstlettermatch =
{
if title not contains %searchString%
{
if S.searchInProcessName()
{
procname := window.getProcessName()
if procname not contains %searchString%
{
continue
}
} else {
continue
}
}
}
else
{
match := matchesSearchString(title, searchString)
match2 :=
if S.searchInProcessName()
{
procname := window.getProcessName()
match2 := matchesSearchString(procname, searchString)
}
if match = && match2 =
continue ; no match
}
;isRunning := window.isRunning()
;M sgBox, %title% -- %isHistory%
filteredWindows.add(window)
} else {
filteredWindows.add(window)
}
}
noWindowsFound := false
amount := filteredWindows.length()
;T oolTip, %amount% windows found
if(amount < 1) {
noWindowsFound := true
filteredWindows.addNew(0, "No windows found", "", 0)
}
;M sgBox, >%search%<
selectedIndex := 1
; if the pattern didn't match any window
if amount = 0
{
; if the search string is empty then we can't do much
if search =
{
Gui, cancel
}
; delete the last character
else
{
if nomatchsound <>
SoundPlay, %nomatchsound%
GoSub, DeleteSearchChar
return
}
}
filteredWindows.removeNonExistent()
amountBefore := amount
amount := xdListView.updateRows(filteredWindows, allWindows, windowHistory, contentType)
searchStringLength := StrLen(searchString)
/*
if(amount < 3) {
originalAmount := filteredWindows.length()
FileAppend, amountAllWindows: %amountAllWindows%`r, logs/log.txt
FileAppend, amountAllWindowsAndHistory: %amountAllWindowsAndHistory%`r, logs/log.txt
FileAppend, amountBefore: %amountBefore%`r, logs/log.txt
FileAppend, amount: %amount%`r, logs/log.txt
FileAppend, originalAmount: %originalAmount%`r, logs/log.txt
FileAppend, ----------------------------------`r, logs/log.txt
}
*/
if(noWindowsFound) {
return
}
if amount = 1
if autoActivateIfOnlyOne
{
if(contentType != S.contentTypeTrayIcons())
{
; only autoactivate if the search string is not empty
; otherwise the gui would close if only one windows is available
; and you think the app doesnt work
maxIdleCounter := 10
counter := 0
if search !=
{
while(A_TimeIdle < 100)
{
Sleep, 10
counter := counter + 1
if(counter > maxIdleCounter) {
break
}
}
if guiActive = 1
{
GoSub, ActivateWindow
}
}
}
}
GoSub, CheckCompletion
return
matchesSearchString(string, search) {
stringlen, search_len, search
index = 1
match =
loop, parse, string, %A_Space%
{
stringleft, first_letter, A_LoopField, 1
; only words beginning with an alphanumeric
; character are taken into account
if first_letter not in 1,2,3,4,5,6,7,8,9,0,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z
continue
stringmid, search_char, search, %index%, 1
if first_letter <> %search_char%
break
index += 1
; no more search characters
if index > %search_len%
{
match = yes
break
}
}
return match
}
CheckCompletion:
if(S.tabComplete() = 0) {
return
}
completion =
; completion is not implemented for first letter match mode
if firstlettermatch <>
return
; determine possible completion if there is
; a search string and there are more than one
; window in the list
if search =
return
amount := filteredWindows.length()
if amount = 1
return
loop
{
nextchar =
loop, %amount%
{
window := filteredWindows.get(A_Index)
title := window.getTitle()
if nextchar =
{
substr = %search%%completion%
stringlen, substr_len, substr
stringgetpos, pos, title, %substr%
;M sgBox, %pos% %substr% %title%
if pos = -1
{
break
}
pos += %substr_len%
;T oolTip, %title% %pos%
; if the substring matches the end of the
; string then no more characters can be completed
stringlen, title_len, title
if pos >= %title_len%
{
pos = -1
break
}
; stringmid has different position semantics
; than stringgetpos. strange...
pos += 1
stringmid, nextchar, title, %pos%, 1
substr = %substr%%nextchar%
;M sgBox, %substr%
}
else
{
stringgetpos, pos, title, %substr%
if pos = -1
{
break
}
}
}
if pos = -1
break
else
{
completion = %completion%%nextchar%
}
}
if completion <>
{
GuiControl,, Edit1, %search%[%completion%]
GuiControl,, InputText, %search%[%completion%]
}
return
WaitForUserToEndTyping:
if(A_TimeIdle > 100) {
SetTimer, WaitForUserToEndTyping, Off
GoSub, ActivateWindow
}
return
;----------------------------------------------------------------------
;
; Delete last search char and update the window list
;
DeleteSearchChar:
if search =
return
StringTrimRight, search, search, 1
GuiControl,, Edit1, %search%
GuiControl,,InputText, %search%
GoSub, RefreshWindowList
return
#If guiActive = 1 and S.useVirtualDesktops() = 1
F3::
window := filteredWindows.get(selectedIndex)
winid := window.getHwnd()
title := window.getTitle()
VD.MoveWindowToDesktopNum("ahk_id" winid,1)
LV_Modify(selectedIndex,, title, 1)
return
F4::
window := filteredWindows.get(selectedIndex)
winid := window.getHwnd()
title := window.getTitle()
VD.MoveWindowToDesktopNum("ahk_id" winid,2)
LV_Modify(selectedIndex,, title, 2)
return
F5::
window := filteredWindows.get(selectedIndex)
winid := window.getHwnd()
title := window.getTitle()
VD.MoveWindowToDesktopNum("ahk_id" winid,3)
LV_Modify(selectedIndex,, title, 3)
return
F10::
window := filteredWindows.get(selectedIndex)
winid := window.getHwnd()
title := window.getTitle()
VD.TogglePinWindow("ahk_id" winid)
desktopNum := VD.getDesktopNumOfWindow("ahk_id" winid)
desktopText := desktopNum
if(desktopNum = 0)
{
desktopText = pinned
}
LV_Modify(selectedIndex,, title, desktopText)
return
#If
#If guiActive = 1 and S.useDelToEndTask()
DEL::
allWindowsContentType := S.contentTypeAllWindows()
if(contentType != S.contentTypeAllWindows()) {
;trayControl.remove(winid)
return
}
window := filteredWindows.get(selectedIndex)
winid := window.getHwnd()
if(!window.getIsRunning()) {
return
}
WinClose, ahk_id %winid%
LV_Delete(selectedIndex)
forceWindowListRefresh = 1
GoSub, RefreshWindowList
return
#If
#If guiActive = 1
F9::
if(autoActivateIfOnlyOne) {
autoActivateIfOnlyOne := false
} else {
autoActivateIfOnlyOne := true
}
GoSub UpdateStatusBar
return
#If
#If guiActive = 1
F1::
if(contentType = S.contentTypeTrayIcons()) {
contentType := S.contentTypeAllWindows()
} else {
contentType := S.contentTypeTrayIcons()
}
lastContentType := contentType
forceWindowListRefresh = 1
GoSub UpdateStatusBar
GoSub RefreshWindowList
return