-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMouseGestureL.ahk
More file actions
3461 lines (3278 loc) · 97.4 KB
/
MouseGestureL.ahk
File metadata and controls
3461 lines (3278 loc) · 97.4 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
#SingleInstance Force
;===============================================================================
;
; MouseGestureL.ahk - Main Script
; Created by lukewarm
; Modified by Pyonkichi
;===============================================================================
;-------------------------------------------------------------------------------
; Initialization Process
;-------------------------------------------------------------------------------
MG_Init:
#MaxHotkeysPerInterval 2000
Process, Priority,, High
MG_Icon = %A_ScriptDir%\Components\MouseGestureL.ico
Menu, Tray, Icon, %MG_Icon%, 1
MG_IsEdit := 0
MG_PluginMenuCount := 0
MG_IsDisableObj := Func("MG_IsDisable")
#Include %A_ScriptDir%\Components\MG_CommonLib.ahk
#Include *i %A_ScriptDir%\Languages\MG_Language.ahk
#Include *i %A_ScriptDir%\Plugins\MG_Plugin.ahk
#Include *i %A_ScriptDir%\Config\MG_Config.ahk
#Include *i %A_ScriptDir%\Config\MG_User.ahk
MG_CheckLanguage()
if (MG_SearchPlugins()) {
Reload
}
MG_CheckConfigFiles()
;...............................................................................
; Register Menu
if (MG_TraySubmenu) {
MG_MenuName := "MGMenu"
}
else {
MG_MenuName := "Tray"
Menu, StdMenu, Standard
Menu, Tray, NoStandard
Menu, Tray, Add, AutoHot&key, :StdMenu
Menu, Tray, Add,
}
Menu, %MG_MenuName%, Add, %MG_LngMenu001%, MG_ToggleEnable
Menu, %MG_MenuName%, Add, %MG_LngMenu002%, MG_NaviToggleEnable
Menu, %MG_MenuName%, Add,
Menu, %MG_MenuName%, Add, %MG_LngMenu003%, MG_Edit
Menu, %MG_MenuName%, Add, %MG_LngMenu004%, MG_EditUser
if (MG_ShowLogs) {
Menu, %MG_MenuName%, Add, %MG_LngMenu005%, MG_CopyLogs
}
if (MG_PluginMenuCount)
{
Loop, %MG_PluginMenuCount% {
Menu, PluginMenu, Add, % MG_PluginMenu%A_Index%_Name, % MG_PluginMenu%A_Index%_Command
}
Menu, PluginMenu, Add,
Menu, PluginMenu, Add, %MG_LngMenu006%, MG_OpenPluginsFolder
Menu, %MG_MenuName%, Add, %MG_LngMenu007%, :PluginMenu
}
else
{
Menu, %MG_MenuName%, Add, %MG_LngMenu006%, MG_OpenPluginsFolder
}
Menu, %MG_MenuName%, Add,
Menu, %MG_MenuName%, Add, %MG_LngMenu008%, MG_ChooseLanguage
Menu, %MG_MenuName%, Add, %MG_LngMenu009%, MG_ShowHelp
Menu, %MG_MenuName%, Add, %MG_LngMenu010%, MG_About
Menu, %MG_MenuName%, Add,
Menu, %MG_MenuName%, Add, %MG_LngMenu011%, MG_Reload
Menu, %MG_MenuName%, Add, %MG_LngMenu012%, MG_Exit
if (MG_TraySubmenu)
{
if (MG_MenuParent) {
Menu, %MG_MenuParent%, Add, %MG_LngMenu013%, :MGMenu
}
else if (A_ScriptName = "MouseGestureL.ahk") {
Menu, Tray, NoStandard
Menu, Tray, Add, %MG_LngMenu013%, :MGMenu
Menu, Tray, Add,
Menu, Tray, Standard
}
}
else {
Menu, Tray, Default, %MG_LngMenu003%
}
;...............................................................................
; Initialize global variables
MG_ScreenDPI := A_ScreenDPI
MG_TriggerCount = 0
MG_Active = 0
MG_Executed = 0
MG_TimedOut = 0
MG_LastTime = 0
MG_ORange = 0.3926990817
MG_ORange1 = 0
MG_ORange2 = 0.2617993878
MG_ORange3 = 0.3926990817
MG_ORange4 = 0.5235987756
MG_ORange5 = 0.7854
MG_NaviPrst = 0
MG_TrailDrawing = 0
MG_hPrevActive = 0
MG_BtnNames := MG_Triggers . "_" . MG_SubTriggers
if (MG_NaviInterval <= 0) {
MG_NaviInterval = 10
}
if (MG_TrailInterval <= 0) {
MG_TrailInterval = 10
}
;...............................................................................
; Initialize Hints and Trail
GoSub, MG_Enable
if (MG_UseExNavi==4) {
MG_LoadIniFile()
}
if (MG_UseNavi) {
MG_NaviEnabled := 1
Menu, %MG_MenuName%, Check, %MG_LngMenu002%
if (MG_UseExNavi) {
MG_CreateExNavi()
}
}
if (MG_ShowTrail) {
MG_InitTrail()
}
MG_InitLog()
MG_SetWinEventHook()
MG_DmyObj := Object("base", Object("__Delete", "MG_EndOperation"))
SetTimer, MG_CancelTimer, 1000
;...............................................................................
; End of Initialization Process
if (A_ThisLabel = "MG_Init") {
return
}
else {
Goto,MG_End
}
;-------------------------------------------------------------------------------
; Cancel Mode Timer
; * It's for in case of failed in catching the button release events
; Implemented by Pyonkichi
;-------------------------------------------------------------------------------
MG_CancelTimer:
MG_CancelMode()
return
MG_CancelMode()
{
global
; Check Unpressed Mouse Buttons
if (MG_TmReleaseTrigger > 0) {
Loop, Parse, MG_CurTriggers, _
{
local szCheckSub := "MG_" . A_LoopField . "_Check"
if (IsLabel(szCheckSub)) {
GoSub, %szCheckSub%
}
}
}
; Hide Hints and Trail
if ((!MG_Active && (A_TickCount>(MG_LastTime+MG_DGInterval+MG_WaitNext)))
|| (MG_Active && MG_TimedOut))
{
MG_StopNavi(0)
MG_StopTrail()
}
}
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;
; Menu Commands
;
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;-------------------------------------------------------------------------------
; Toggle Gesture Enabled and Disabled
; Implemented by lukewarm
; Modified by Pyonkichi
;-------------------------------------------------------------------------------
MG_ToggleEnable:
if(MG_Enabled){
Gosub,MG_Disable
TrayTip, MouseGestureL, %MG_LngTooltip002%
}else{
GoSub,MG_Enable
TrayTip, MouseGestureL, %MG_LngTooltip001%
}
SetTimer, MG_HideTrayTip, -1000
return
;-------------------------------------------------------------------------------
; Enable Gesture
; Implemented by lukewarm
;-------------------------------------------------------------------------------
MG_Enable:
MG_Enabled=1
Loop,Parse,MG_Triggers,_
GoSub,MG_%A_LoopField%_Enable
Menu,%MG_MenuName%,Check,%MG_LngMenu001%
Menu, Tray, Icon, %MG_Icon%, 1
if (MG_ShowTrail && MG_DrawTrailWnd) {
Gui, MGW_Trail:Show, NA
}
return
;-------------------------------------------------------------------------------
; Disable Gesture
; Implemented by lukewarm
;-------------------------------------------------------------------------------
MG_Disable:
if(MG_Active){
SetTimer,MG_Disable,-500
}else if(MG_Enabled){
MG_Enabled=0
Loop,Parse,MG_Triggers,_
GoSub,MG_%A_LoopField%_Disable
Menu,%MG_MenuName%,Uncheck,%MG_LngMenu001%
Menu, Tray, Icon, %A_WinDir%\system32\shell32.dll,110
if (MG_ShowTrail && MG_DrawTrailWnd) {
Gui, MGW_Trail:Hide
}
}
return
;-------------------------------------------------------------------------------
; Edit Gesture Configurations
; Implemented by lukewarm
; Modified by Pyonkichi
;-------------------------------------------------------------------------------
MG_Edit:
MG_Edit()
return
;-------------------------------------------------------------------------------
; Edit User Extension Script
; Implemented by lukewarm
; Modified by Pyonkichi
;-------------------------------------------------------------------------------
MG_EditUser:
MG_EditUser()
return
MG_EditUser()
{
global
if(!FileExist(A_ScriptDir . "\Config\MG_User.ahk"))
{
local szContents
szContents=
(LTrim
%MG_LngOthers001%
;----- %MG_LngOthers002% ------------------------------------------------
if (!MG_IsEdit) {
; %MG_LngOthers004%
} else {
; %MG_LngOthers005%
}
; %MG_LngOthers006%
;-------------------------------------------------------------------------------
Goto, MG_User_End
;----- %MG_LngOthers003% ------------------------------------------------
;-------------------------------------------------------------------------------
MG_User_End:
)
FileAppend, %szContents%, %A_ScriptDir%\Config\MG_User.ahk, UTF-8
}
local szEditor
if (MG_ScriptEditor != "") {
szEditor := """" . MG_ScriptEditor . """"
}
else {
szEditor := "notepad"
}
MG_RunAsUser(szEditor . " " . A_ScriptDir . "\Config\MG_User.ahk")
}
;-------------------------------------------------------------------------------
; Open Plugins Folder
; Implemented by Pyonkichi
;-------------------------------------------------------------------------------
MG_OpenPluginsFolder:
Run, %A_ScriptDir%\Plugins
return
;-------------------------------------------------------------------------------
; Show Choose Language Dialog Box
; Implemented by Pyonkichi
;-------------------------------------------------------------------------------
MG_ChooseLanguage:
MG_CheckLanguage(1)
return
;-------------------------------------------------------------------------------
; Show Help Document
; Implemented by Pyonkichi
;-------------------------------------------------------------------------------
MG_ShowHelp:
MG_ShowHelp()
return
;-------------------------------------------------------------------------------
; Show About Dialog Box
; Implemented by Pyonkichi
;-------------------------------------------------------------------------------
MG_About:
MG_ShowAboutDlg()
return
MG_ShowAboutDlg()
{
global
Gui, MGW_About:New
Gui, MGW_About:-MaximizeBox -MinimizeBox +LastFound
Gui, MGW_About:Margin, , 12
Gui, MGW_About:Add, Picture, w48 h-1, %MG_Icon%
Gui, MGW_About:Font, S12
Gui, MGW_About:Add, Text, x+10 yp+4 vTAppName Section, MouseGestureL.ahk Version %MG_Version%
Gui, MGW_About:Font
Gui, MGW_About:Add, Text, xs+8 y+6, [ AutoHotkey Version %A_AhkVersion% ]
Gui, MGW_About:Add, Text, xs+8 y+10, Copyright (C) 2007-2008 lukewarm
Gui, MGW_About:Add, Text, xs+8 y+4, Copyright (C) 2011-2020 Pyonkichi
Gui, MGW_About:Font, S16 cBlue w1000, Wingdings 3
Gui, MGW_About:Add, Text, xs+8 y+6 gMGW_AboutWebsite, % Chr(0xC7)
Gui, MGW_About:Font
Gui, MGW_About:Font, Underline cBlue
Gui, MGW_About:Add, Text, x+1 yp+8 vAboutGoWebsite gMGW_AboutWebsite, HomePage
Gui, MGW_About:Font
Gui, MGW_About:Font, S12 cBlue, Wingdings
Gui, MGW_About:Add, Text, x+15 yp-2 gMGW_AboutContact, % Chr(0x2A)
Gui, MGW_About:Font
Gui, MGW_About:Font, Underline cBlue
Gui, MGW_About:Add, Text, x+1 yp+2 vAboutGoForum gMGW_AboutContact, Contact
Gui, MGW_About:Font
local Bx, Bw:=80
GuiControlGet, rcCtrl, MGW_About:Pos, TAppName
Bx := rcCtrlX + rcCtrlW - Bw
Gui, MGW_About:Add, Button, x%Bx% y+16 w%Bw% Default gMGW_AboutGuiClose, OK
Gui, MGW_About:Show, Autosize
return
MGW_AboutWebsite:
MGW_AboutContact:
local home := "https://hp.vector.co.jp/authors/VA018351/" (MG_Language="Japanese" ? "" : "en/") "mglahk.html"
, contact := "https://www.autohotkey.com/boards/viewtopic.php?f=6&t=31859"
Run, % (A_ThisLabel="MGW_AboutWebsite") ? home : contact
MGW_AboutGuiClose:
MGW_AboutGuiEscape:
Gui, MGW_About:Destroy
return
}
;-------------------------------------------------------------------------------
; Reload Gesture Configurations
; Implemented by lukewarm
; Modified by Pyonkichi
;-------------------------------------------------------------------------------
MG_Reload:
MG_Reload()
return
;-------------------------------------------------------------------------------
; Exit Application
; Implemented by lukewarm
;-------------------------------------------------------------------------------
MG_Exit:
ExitApp
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;
; Gesture Recognition
;
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;-------------------------------------------------------------------------------
; Get cursor position and target information
; カーソル位置・ターゲットの情報を取得
; Implemented by lukewarm
; Modified by Pyonkichi
;-------------------------------------------------------------------------------
MG_GetMousePosInfo()
{
global
MG_TickCount:=A_TickCount
CoordMode,Mouse,Screen
MouseGetPos, MG_X, MG_Y, MG_HWND, MG_HCTL, 3
SendMessage,0x84,0,% MG_Y<<16|MG_X,,ahk_id %MG_HCTL%
if (ErrorLevel == 4294967295) {
MouseGetPos,,,,MG_HCTL, 2
}
MG_Cursor := MG_GetCursor()
if (MG_ActiveAsTarget) {
WinGet, MG_HWND, ID, A
MG_HCTL := MG_GetFocus()
}
IfWinExist,ahk_id %MG_HWND%,,,,{
WinGetClass, MG_WClass
WinGet, MG_PID, PID
WinGet, MG_Exe, ProcessName
WinGetTitle, MG_Title
}
WinGetClass, MG_CClass, ahk_id %MG_HCTL%
if (MG_CClass = "Button") {
MG_CorrectDlgCtrlHandle()
}
}
;-------------------------------------------------------------------------------
; Correct target control handle in a dialog box
; Implemented by Pyonkichi
;-------------------------------------------------------------------------------
MG_CorrectDlgCtrlHandle()
{
global MG_X, MG_Y, MG_HCTL, MG_WClass, MG_ActiveAsTarget
if (MG_WClass!="#32770" || !MG_IsNewOS() || MG_ActiveAsTarget) {
return
}
rc := DllCall("GlobalAlloc", "UInt",0x40, "UInt",16, "Ptr")
hParent := DllCall("GetParent", "Ptr",MG_HCTL)
hCtrl := MG_HCTL
while (hCtrl)
{
hCtrl := DllCall("FindWindowEx", "Ptr",hParent, "Ptr",hCtrl, "Ptr",0, "Ptr",0, "Ptr")
if (!hCtrl) {
break
}
DllCall("GetWindowRect", "Ptr",hCtrl, "Ptr",rc)
if (DllCall("PtInRect", "Ptr",rc, "Int64",MG_Y<<32|MG_X, "Ptr"))
{
WinGet, dwStyle, Style, ahk_id %hCtrl%
if (dwStyle & 0x10000000) {
MG_HCTL := hCtrl
}
}
}
WinGetClass, MG_CClass, ahk_id %MG_HCTL%
DllCall("GlobalFree", "Ptr",rc)
}
;-------------------------------------------------------------------------------
; Compare Strings
; str1 : First string to be compared.
; str2 : Second string to be compared.
; method : Matching rule
; : 1 = Match Exact Word
; : 2 = Match Partial Word
; : 3 = Match Prefix
; : 4 = Match Suffix
; : 5 = Use Regular Expression
; Implemented by Pyonkichi
;-------------------------------------------------------------------------------
MG_StrComp(str1, str2, method=1)
{
if (method == 2) {
return (Instr(str1, str2) != 0)
}
else if (method == 3) {
return (Instr(str1, str2) == 1)
}
else if (method == 4) {
start := StrLen(str1) - StrLen(str2) + 1
return (Instr(str1, str2, false, start) == start)
}
else if (method == 5) {
return (RegExMatch(str1, str2) != 0)
}
return (str1 = str2)
}
;-------------------------------------------------------------------------------
; Process trigger-down actions
; トリガー押し下げの報告を受け付け
; Implemented by lukewarm
; Modified by Pyonkichi
;-------------------------------------------------------------------------------
MG_TriggerDown(name)
{
global
Critical
if(!InStr(MG_CurTriggers,name . "_"))
{
MG_TriggerCount++
MG_UnpressCnt%name% := 0
MG_CurTriggers=%MG_CurTriggers%%name%_
if (MG_Active && MG_TimedOut)
{
GoSub,MG_%name%_Down
}
else if (MG_TriggerCount==1)
{
; Begin to process gesture at first trigger-down
; 最初のトリガーの場合、ジェスチャー処理を実行
if (A_TickCount>(MG_LastTime+MG_DGInterval+MG_WaitNext))
{
MG_Gesture = %name%_
MG_1stTrigger := MG_Gesture
}
else
{
MG_Gesture = %MG_Gesture%%name%_
}
MG_GetMousePosInfo()
MG_NowX:=MG_PreX:=MG_TX:=MG_TL:=MG_TR:=MG_X
MG_NowY:=MG_PreY:=MG_TY:=MG_TT:=MG_TB:=MG_Y
MG_PrevTime := A_TickCount
MG_PrevGesture := ""
MG_NaviPrstStr := ""
if (MG_IsDisableObj.()) {
GoSub,MG_%name%_Down
}
else {
MG_StartNavi()
MG_StartTrail()
MG_Aborted:=0
MG_Check()
if (MG_Aborted) {
MG_StopNavi(0)
MG_StopTrail()
GoSub,MG_%name%_Down
} else {
MG_Recognition(1)
}
}
}
else
{
; Otherwise execute gesture
; それ以外の場合、ジェスチャーの発動判定
MG_Recognition()
MG_Gesture=%MG_Gesture%%name%_
MG_Check()
MG_PreX:=MG_NowX, MG_PreY:=MG_NowY, MG_PrevTime:=A_TickCount
}
}
}
;-------------------------------------------------------------------------------
; Process trigger-up actions
; トリガー押し上げの報告を受け付け
; Implemented by lukewarm
; Modified by Pyonkichi
;-------------------------------------------------------------------------------
MG_TriggerUp(name)
{
local px, py
Critical
if (!RegExMatch(MG_CurTriggers,"(?<=_|^)" . name . "_")) {
return
}
if (!MG_Aborted) {
MG_Recognition()
}
MG_TriggerCount := (MG_TriggerCount>0) ? (MG_TriggerCount-1) : 0
MG_CurTriggers := RegExReplace(MG_CurTriggers,"(?<=_|^)" . name . "_")
if(!MG_Active || MG_TimedOut)
{
GoSub, MG_%name%_Up
}
else
{
MG_Gesture = %MG_Gesture%_
if (!MG_Aborted) {
MG_Check()
}
if (MG_TriggerCount < 1)
{
if (MG_NaviPrstStr)
{
MG_NaviPrst := 1
SetTimer, MG_NaviPersistTimer, %MG_NaviPersist%
}
MG_StopNavi(0)
MG_StopTrail()
if ((!MG_Executed)
&& (!MG_DisableDefMB || (name!="MB"))
&& (!MG_DisableDefX1B || (name!="X1B"))
&& (!MG_DisableDefX2B || (name!="X2B"))
&& (!MG_PrvntCtxtMenu || (MG_Gesture==name "__")))
{
; Emulate trigger if gesture is not executed
; ジェスチャー未発動の場合、トリガー操作をエミュレート
CoordMode,Mouse,Screen
SetMouseDelay,-1
BlockInput,On
MouseGetPos,px,py
MouseMove,%MG_X%,%MG_Y%,0
GoSub,MG_%name%_Down
MouseMove,%px%,%py%,0
Sleep,1
GoSub,MG_%name%_Up
BlockInput,Off
}
}
}
}
;-------------------------------------------------------------------------------
; Process button-press actions
; ボタン操作の報告を受け付け
; Implemented by lukewarm
; Modified by Pyonkichi
;-------------------------------------------------------------------------------
MG_ButtonPress(name)
{
global
if (MG_Active && MG_TimedOut)
{
Gosub,MG_%name%_Press
}
else
{
if(!MG_Active && (A_TickCount>(MG_LastTime+MG_DGInterval+MG_WaitNext)))
{
MG_GetMousePosInfo()
if (MG_IsDisableObj.()) {
Gosub,MG_%name%_Press
}
else {
MG_Gesture=%name%_
MG_Aborted:=0,MG_WaitNext:=0,MG_Executed:=0,MG_TimedOut:=0
MG_NowX:=MG_PreX:=MG_X, MG_NowY:=MG_PreY:=MG_Y,MG_PrevTime:=A_TickCount
if(!MG_Check()){
Gosub,MG_%name%_Press
}
}
}
else
{
MG_Recognition()
MG_Gesture=%MG_Gesture%%name%_
if(!MG_Check()){
Gosub,MG_%name%_Press
}
MG_PreX:=MG_NowX, MG_PreY:=MG_NowY, MG_PrevTime:=A_TickCount
}
}
}
;-------------------------------------------------------------------------------
; Check gesture updates
; ジェスチャーが更新される度に実行
; Implemented by lukewarm
; Modified by Pyonkichi
;-------------------------------------------------------------------------------
MG_Check(g="")
{
local ges,ex,tmp
MG_LastTime:=A_TickCount
if (StrLen(MG_Gesture)>MG_MaxLength)
{
; Gesture is too long
; ジェスチャーの長さが定義されている最大長を超えた
MG_Gesture=%MG_CurTriggers%
}
else
{
if (g) {
ges:=g
} else {
ges:=MG_Gesture
}
if (IsLabel("MG_Gesture_" . ges))
{
if (MG_NaviPersist > 0) {
MG_NaviPrstStr := MG_Gesture
}
IfWinExist,ahk_id %MG_HWND%,,,,{
}
ex := MG_Executed++
(MG_ShowLogs && !g) ? MG_UpdateLogs(ges) :
Gosub,MG_Gesture_%ges%
if (ex != MG_Executed) {
if (!g) {
MG_Gesture := MG_CurTriggers
}
return 1
}
else {
return (MG_WaitNext != 0)
}
}
}
MG_ShowLogs ? MG_UpdateLogs() :
return 0
}
;-------------------------------------------------------------------------------
; Recognition function
; 認識処理の本体
; fInit : 1 = Initialize recognition process
; 0 = Recognition only
; Implemented by lukewarm
; Modified by Pyonkichi
;-------------------------------------------------------------------------------
MG_Recognition(fInit=0)
{
global
static px, py, plx, ply, d1, d2, orange, next_timeout
local powx, powy
;...........................................................................
; Initialization of recognition process
if (fInit)
{
MG_Active:=1, MG_Aborted:=0, MG_WaitNext:=0, MG_Executed:=0, MG_TimedOut:=0
px:=plx:=MG_X, py:=ply:=MG_Y, d1:="", d2:=""
orange:=MG_ORange%MG_ORangeDefault%, next_timeout:=A_TickCount+MG_Timeout
MG_ScreenDPI := MG_GetDpiFromPoint(MG_X, MG_Y)
Loop,Parse,MG_SubTriggers,_
{
GoSub,MG_%A_LoopField%_Enable
}
SetTimer, MG_RecogTimer, %MG_Interval%
}
;...........................................................................
; Recognition process
CoordMode,Mouse,Screen
MouseGetPos,MG_NowX,MG_NowY
if (MG_TriggerCount < 1)
{
; Release all triggers : 全てのトリガが離された
SetTimer, MG_RecogTimer, Off
MG_Active:=0,MG_TriggerCount:=0,MG_CurTriggers:=""
Loop, Parse, MG_SubTriggers, _
{
GoSub,MG_%A_LoopField%_Disable
}
MG_StopNavi(0)
MG_StopTrail()
}
else if ((MG_X-MG_NowX)**2+(MG_Y-MG_NowY)**2 < MG_TimeoutThreshold**2)
{
; Tiny movement : 微小な動き
next_timeout:=A_TickCount+MG_Timeout
}
else if (!MG_TimedOut
&& (MG_Aborted || ((A_TickCount>next_timeout) && (MG_Executed==0))))
{
; Time out when moving : 移動中にタイムアウト
MG_StopNavi(0)
MG_StopTrail()
Critical
SetMouseDelay,-1
MG_TimedOut=1
BlockInput,On
MouseMove,%MG_X%,%MG_Y%,0
Loop,Parse,MG_CurTriggers,_
{
if (A_LoopField) {
GoSub,MG_%A_LoopField%_Down
}
}
MouseMove,%MG_NowX%,%MG_NowY%,0
BlockInput,Off
Critical,Off
}
else if(!MG_TimedOut && ((powx:=(MG_NowX-px)**2)+(powy:=(MG_NowY-py)**2) >= MG_Threshold**2))
{
; Check Normal Movement : 移動検出
if (MG_8Dir) {
if (orange > Abs(0.7853981634-Abs(ATan((MG_NowX-px)/(MG_NowY-py))))) {
d2 := (MG_NowX>px) ? ((MG_NowY>py) ? 3 : 9) : ((MG_NowY>py) ? 1 : 7)
} else {
d2 := (powx>powy) ? ((MG_NowX>px) ? 6 : 4) : ((MG_NowY>py) ? 2 : 8)
}
}
else {
d2:= (powx>powy) ? ((MG_NowX>px) ? "R":"L") : ((MG_NowY>py) ? "D":"U")
}
; Judge Normal Movement
local fChanged := 0
if (d1 != d2) {
fChanged := 1
}
else {
; Check Long Movement
if (MG_8Dir) {
fChanged := ((MG_NowX-plx)**2+(MG_NowY-ply)**2 >= MG_LongThreshold**2)
} else if (powx > powy) {
fChanged := (Abs(MG_NowX-plx) >= MG_LongThresholdX)
} else {
fChanged := (Abs(MG_NowY-ply) >= MG_LongThresholdY)
}
}
; Judge Overall Movement
if (fChanged)
{
MG_Gesture=%MG_Gesture%%d2%
if (MG_8Dir)
{
if (d2 & 1) {
orange := MG_ORange%MG_ORangeB%
} else {
orange := MG_ORange%MG_ORangeA%
}
}
plx:=px, ply:=py
d1 := MG_Check() ? "" : d2
;MG_PreX:=MG_NowX, MG_PreY:=MG_NowY, MG_PrevTime:=A_TickCount
}
MouseGetPos,px,py
next_timeout:=A_TickCount+MG_Timeout
MG_PreX:=px, MG_PreY:=py, MG_PrevTime:=A_TickCount
}
}
MG_RecogTimer:
MG_Recognition()
return
;-------------------------------------------------------------------------------
; Emulate the mouse button events
; Implemented by Pyonkichi
;-------------------------------------------------------------------------------
MG_SendButton(name, btn, mode="")
{
global
SetMouseDelay,-1
if (MG_%name%_Enabled) {
GoSub,MG_%name%_Disable
MG_%name%_Disabled := 1
} else {
MG_%name%_Disabled := 0
}
Send, % "{Blind}{" . btn . (mode ? " "mode : "") . "}"
if (MG_%name%_Disabled) {
GoSub,MG_%name%_Enable
}
}
;-------------------------------------------------------------------------------
; Check unexpected mouse button holding
; Implemented by Pyonkichi
;-------------------------------------------------------------------------------
MG_CheckButton(name, btn)
{
global
if (MG_Active && MG_TimedOut) {
MG_UnpressCnt%name%++
if (MG_UnpressCnt%name% > MG_TmReleaseTrigger) {
MG_UnpressCnt%name% := 0
MG_TriggerUp(name)
}
} else {
MG_UnpressCnt%name% := 0
}
}
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;
; Script Control Functions
;
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;-------------------------------------------------------------------------------
; Abort the gesture
; Implemented by lukewarm
;-------------------------------------------------------------------------------
MG_Abort()
{
global
MG_Aborted := 1
}
;-------------------------------------------------------------------------------
; Abort the recognition
; Implemented by lukewarm
;-------------------------------------------------------------------------------
MG_Cancel()
{
MG_Wait(0)
}
;-------------------------------------------------------------------------------
; Wait for the next gesture
; Implemented by lukewarm
;-------------------------------------------------------------------------------
MG_Wait(ms=0)
{
global
MG_Executed--
MG_WaitNext := ms
}
;-------------------------------------------------------------------------------
; Delayed Execution
; Implemented by lukewarm
;-------------------------------------------------------------------------------
MG_Timer(ms=0)
{
global
if(MG_TimerMode==-1){
MG_TimerMode=0
return 0
}
MG_TimerGesture:=MG_Gesture
if(ms){
if(ms>0){
MG_TimerMode=1
SetTimer,MG_TimerExecute,% -ms
}else{
MG_TimerMode=2
MG_Executed--
MG_WaitNext:=-ms
SetTimer,MG_TimerExecute,% ms
}
}else{
MG_TimerMode=3
SetTimer,MG_TimerExecute,% -MG_Interval
}
return 1
}
MG_TimerExecute:
if((MG_TimerMode==3) && MG_Active){
SetTimer,MG_TimerExecute,% -MG_Interval
return
}
if((MG_TimerMode!=2) || (MG_Gesture=MG_TimerGesture)){
MG_TimerMode=-1
MG_Check(MG_TimerGesture)
}else{
MG_TimerMode=0
}
return
;-------------------------------------------------------------------------------
; Execute the action when gesture recognition is finished
; Implemented by lukewarm
;-------------------------------------------------------------------------------
MG_Defer()
{
return !MG_Timer()
}
;-------------------------------------------------------------------------------
; Repeatedly Execution
; Implemented by lukewarm
;-------------------------------------------------------------------------------
MG_While(ms=20)
{
global
if(!MG_WhileState){
MG_WhileGesture:=MG_Gesture
MG_WhileTrrigers:=MG_Triggers
MG_WhileStartTime:=A_TickCount
if(ms<1){
MG_WhileInterval:=MG_Interval
MG_WhileState:=2
}else{
MG_WhileInterval:=ms
MG_WhileState:=1
}
}else if(MG_WhileState=-1){
MG_WhileState:=0
return 0
}
SetTimer,MG_WhileExecute,% -MG_WhileInterval
return 1
}
MG_WhileExecute:
if(MG_Active && InStr(MG_Triggers,MG_WhileTrrigers)=1){
SetTimer,MG_WhileExecute,% -MG_WhileInterval
if(MG_WhileState=1){
MG_Check(MG_WhileGesture)
}
return
}else{
MG_WhileState:=-1
MG_Check(MG_WhileGesture)
}