-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathkeymouse.ahk
790 lines (663 loc) · 25.8 KB
/
keymouse.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
AUTOEXEC_keymouse: ; Workaround for Autohotkey's ugly auto-exec feature. Must be first line.
global km_PinnedMousePos := {} ; .x .y
global km_T3recnames := ["PrnScrn", "ScroLock", "Brk"]
; recname: RECorded name in the ini as INI-key.
; The INI file has something like:
;
; [T3keymouse]
; PrnScrn=Left
; ScroLock=Right
global km_radiosel_PrnScrn
global km_radiosel_ScroLock
global km_radiosel_Brk
; cannot make these 3 lines into a for-cycle, because concatenating GLOBAL-varname is not allowed(at least in 1.1.19.02)
global km_dict_T3obj := {}
km_init_arT3obj() ; call the function
km_init_arT3obj() ; define the function
{
km_dict_T3obj.PrnScrn := {}
o := km_dict_T3obj.PrnScrn ; o is just a reference to km_dict_T3obj.PrnScrn, not a copy
o.friendlyname := "PrintScreen" ; (const)
o.ahkname := "SC137" ; use "PrintScreen" sometimes cause weired problem, so SC-code (const)
o.action := "" ; default as original key action
km_dict_T3obj.ScroLock := {}
o := km_dict_T3obj.ScroLock
o.friendlyname := "ScrollLock"
o.ahkname := "SC046" ; use "ScrollLock" sometimes cause weired problem
o.action := "Left" ; default as left click
km_dict_T3obj.Brk := {}
o := km_dict_T3obj.Brk
o.friendlyname := "Pause"
o.ahkname := "SC045" ;"Pause"
o.action := "Right" ; default as right click
; [2019-10-08] Memo: On Autohotkey 1.1.24.05, using "Pause" as o.ahkname will cause problem:
; Call dev_DefineHotkey with 1st param "$Pause", and Hotkey_Handler_global sees A_ThisHotkey as "Pause",
; -- the "$" prefix is lost. Using "SC045" fixes this problem(ahk bug?), and we'll se A_ThisHotkey as "$SC045".
; MsgBox, % km_dict_T3obj.PrnScrn.ahkname . " // " . km_dict_T3obj.ScroLock.ahkname
}
;;; internal globals:
global kmc_indents := " " ; c implies constant
global kmc_ybiggap := "y+14 "
global km_cfgfile := "keymouse.ini"
global km_isIniLoaded := false
global km_isRShiftArrowNudge := false
global km_RShiftNudgeUnit := "10"
global km_isKeypadNudge := false
global km_KeypadNudgeUnit := "10"
global km_isNumpadSpecial := false
global km_isAppsEasyMouse := false
global kmc_EasymouseLiteHint := "easymouse0"
global kmc_EasymouseLiteHintW, kmc_EasymouseLiteHintE, kmc_EasymouseLiteHintN, kmc_EasymouseLiteHintS ; west/east/north/south
global kmc_EasymouseLiteHint_q
global km_EasymouseWestKey := "SC137" ; (SC137 is PrintScreen) will write ``SC137`` into INI and must be true-and-valid AHK keyname
global km_EasymouseWest_radiosel
global km_EasymouseWest_fraction := "0.15"
;
global km_EasymouseEastKey := "SC046" ; SC046 is ScrollLock
global km_EasymouseEast_radiosel
global km_EasymouseEast_fraction := "0.85"
;
global km_EasymouseNorthKey := "Home"
global km_EasymouseNorth_radiosel
global km_EasymouseNorth_fraction := "0.3"
;
global km_EasymouseSouthKey := "End"
global km_EasymouseSouth_radiosel
global km_EasymouseSouth_fraction := "0.7"
; Systray menu-items
global km_menutext_MouseWiggle := "Enable Mouse-wiggle"
km_AddSystrayMenuItem()
km_LoadIni()
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
return ; End of auto-execute section.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; 2010-01-04 http://www.autohotkey.com/forum/viewtopic.php?p=321498
;MButton:: Send ^c
; 2011-12-28 http://www.autohotkey.com/forum/viewtopic.php?p=500772
; right click while holding left mouse down
;~LButton & RButton::Send ^v
/*
km_IsIniExist()
{
if(FileExist(km_cfgfile))
return true
else
return false
}
*/
km_T3QueryChecked(recname, button)
{
if(km_dict_T3obj[recname].action==button)
return " Checked" ; deliberate add a space ahead
else
return " "
}
km_EasymouseLiteChecked(direction, ahkname)
{
varname = km_Easymouse%direction%Key
if(%varname%==ahkname)
return " Checked"
else
return " "
}
km_EasymouseLite_sel2keyname(dxn, is_updatevar:=true)
{
; The mapping should sync with Gui: ``vkm_EasymouseWest_radiosel Group``
dxnsel_varname = km_Easymouse%dxn%_radiosel
dxnkey_varname = km_Easymouse%dxn%Key
sel := %dxnsel_varname%
if(sel==1)
hotname := "SC137"
else if(sel==2)
hotname := "SC046"
else if(sel==3)
hotname := "Pause"
else if(sel==4)
hotname := (dxn=="West" or dxn=="North") ? "PgUp" : "PgDn"
else if(sel==5)
hotname := (dxn=="West" or dxn=="North") ? "Home" : "End"
else
hotname := ""
%dxnkey_varname% := hotname
return hotname
}
km_EasyMouseLite(fractionx, fractiony)
{
; just a wrapper for easy debugging
; tooltip, % "km_EasyMouseLite x=" . fractionx . " y=" . fractiony
km_Easymouse(fractionx, fractiony)
}
km_DefineEasymouseLiteHotkeys(is_save_ini:=false, is_disable_old_hotkey:=false)
{
; "Lite" means West,East,North,South only, instead of eight directions.
/* Don't need this now, because I enforce ahk Reload to flush old hotkeys.
if(is_disable_old_hotkey)
{
; Remove all "relating" AHK hotkeys first.
; Note a side effect here: User's already effective "conflicting" hotkeys will be removed as well.
; Workaround: Reload the whole AmHotkey.ahk, then is_disable_old_hotkey will be false and the remove actions
; will be bypassed.
apphots := ["SC137", "SC046", "Pause", "Home", "End", "PgUp", "PgDn"] ; this is hard-coded, should manually sync
for index, hot in apphots
{
try {
dev_DefineHotkey("AppsKey & " . hot, "")
}
catch {
;If, for example "AppsKey & Home" is not defined as hotkey yet, executing
;
; Hotkey, AppsKey & Home, , Off
;
;will assert runtime error, but not a true error by our purpose.
;So I use catch to bypass this error.
}
}
}
*/
ardxn := ["West", "East", "North", "South"]
for index, dxn in ardxn
{
vHotname = km_Easymouse%dxn%Key
vFraction = km_Easymouse%dxn%_fraction
if(%vFraction%<0) {
MsgBox, % dxn . " bad(<0) " . %vFraction%
%vFraction% := "0.01"
}
else if(%vFraction%>1) {
MsgBox, % dxn . " bad(>1) " . %vFraction%
%vFraction% := "0.99"
}
; Define dynamic hotkeys for Easymouse lite.
if(%vHotname%)
{
;XX MsgBox, % "3333 vHotname=" . vHotname . " / " . %vHotname% . " / " . %vFraction%
if(dxn=="West" or dxn=="East")
dev_DefineHotkey("AppsKey & " . %vHotname%, "km_EasyMouseLite", %vFraction%, 1/2)
else ; North or South
dev_DefineHotkey("AppsKey & " . %vHotname%, "km_EasyMouseLite", 1/2, %vFraction%)
;XX MsgBox, 4444 vHotname=%vHotname% (%dxn%)
}
if(is_save_ini)
km_IniWrite("EasyMouse", dxn . "Fraction", %vFraction%)
}
}
km_IniRead(section, key, default)
{
if(default=="") {
default := A_Space
; This is the official way to pass a null-string as default value.
; If you use the "regular" way(use %default%), outputvar will be "ERROR" .
}
IniRead, outputvar, %km_cfgfile%, %section%, %key%, %default%
return outputvar
}
km_LoadIni()
{
if(not FileExist(km_cfgfile))
{
return
}
;;;;
for index, recname in km_T3recnames
{
o := km_dict_T3obj[recname]
strAction := km_IniRead("T3keymouse", recname, "")
o.action := strAction
if(strAction) ; if not ""
dev_DefineHotkey("$" . o.ahkname, "Km_T3key_do_action", o.ahkname, strAction)
; For the key(s) that acts as left mouse click, we define Shift+Ctrl+<key> and Shift+<key>
; as [save current mouse position] and [restore mouse to the saved position]
if(strAction=="Left")
{
dev_DefineHotkey("+^" . o.ahkname, "km_RememberPinPos")
dev_DefineHotkey("+" . o.ahkname, "km_RestorePinPos")
}
}
;;;;
km_isRShiftArrowNudge := km_IniRead("MouseNudge", "isRShiftArrowNudge", 0) ; 0=false
km_RShiftNudgeUnit := km_IniRead("MouseNudge", "RShiftNudgeUnit", 10)
if(km_isRShiftArrowNudge)
{
dev_DefineHotkey("$>+Up", "km_RShiftNudge_do", "Up", 0, -1)
dev_DefineHotkey("$>+Down", "km_RShiftNudge_do", "Down", 0, 1)
dev_DefineHotkey("$>+Left", "km_RShiftNudge_do", "Left", -1, 0)
dev_DefineHotkey("$>+Right", "km_RShiftNudge_do", "Right", 1, 0)
}
;;;;
km_isKeypadNudge := km_IniRead("MouseNudge", "isKeypadNudge", 0) ; 0=false
km_KeypadNudgeUnit := km_IniRead("MouseNudge", "KeypadNudgeUnit", 10)
if(km_isKeypadNudge)
{
dev_DefineHotkey("$NumpadHome", "km_KeypadNudge_do", "NumpadHome", -1, -1)
dev_DefineHotkey("$NumpadUp", "km_KeypadNudge_do", "NumpadUp", 0, -1)
dev_DefineHotkey("$NumpadPgUp", "km_KeypadNudge_do", "NumpadPgUp", 1, -1)
dev_DefineHotkey("$NumpadLeft", "km_KeypadNudge_do", "NumpadLeft", -1, 0)
dev_DefineHotkey("$NumpadRight", "km_KeypadNudge_do", "NumpadRight", 1, 0)
dev_DefineHotkey("$NumpadEnd", "km_KeypadNudge_do", "NumpadEnd", -1, 1)
dev_DefineHotkey("$NumpadDown", "km_KeypadNudge_do", "NumpadDown", 0, 1)
dev_DefineHotkey("$NumpadPgDn", "km_KeypadNudge_do", "NumpadPgDn", 1, 1)
; Use Numpad / to simulate mouse Lbutton pressing down, * to release Lbutton.
; This helps a lot when we need pixel accurate mouse movement.s
dev_DefineHotkey("$NumpadDiv", "km_KeypadNudge_do", "NumpadDiv", 0, 0)
dev_DefineHotkey("$NumpadMult", "km_KeypadNudge_do", "NumpadMult", 0, 0)
}
;;;;
km_isNumpadSpecial := km_IniRead("NumpadSpecial", "isNumpadSpecial", 0) ; 0=false
if(km_isNumpadSpecial)
{
dev_DefineHotkey("$NumpadDiv", "km_NumpadSpecial_do", "NumpadDiv")
dev_DefineHotkey("$NumpadMult", "km_NumpadSpecial_do", "NumpadMult")
dev_DefineHotkey("$NumpadSub", "km_NumpadSpecial_do", "NumpadSub")
dev_DefineHotkey("$NumpadAdd", "km_NumpadSpecial_do", "NumpadAdd")
dev_DefineHotkey("$NumpadIns", "km_NumpadSpecial_do", "NumpadIns")
}
;;;;
km_isAppsEasyMouse := km_IniRead("EasyMouse", "isAppsEasyMouse", 0) ; 0=false
if(km_isAppsEasyMouse)
{
dev_DefineHotkey("AppsKey & NumpadHome" , "km_EasyMouseNumpad", 1/6, 1/4)
dev_DefineHotkey("AppsKey & NumpadUp" , "km_EasyMouseNumpad", 1/2, 1/4)
dev_DefineHotkey("AppsKey & NumpadPgUp" , "km_EasyMouseNumpad", 5/6, 1/4)
dev_DefineHotkey("AppsKey & NumpadLeft" , "km_EasyMouseNumpad", 1/6, 1/2)
dev_DefineHotkey("AppsKey & NumpadClear" , "km_EasyMouseNumpad", 1/2, 1/2)
dev_DefineHotkey("AppsKey & NumpadRight" , "km_EasyMouseNumpad", 5/6, 1/2)
dev_DefineHotkey("AppsKey & NumpadEnd" , "km_EasyMouseNumpad", 1/6, 3/4)
dev_DefineHotkey("AppsKey & NumpadDown" , "km_EasyMouseNumpad", 1/2, 3/4)
dev_DefineHotkey("AppsKey & NumpadPgDn" , "km_EasyMouseNumpad", 5/6, 3/4)
}
km_EasymouseWestKey := km_IniRead("EasyMouse", "EasymouseWestKey", "")
;msgbox, 444444444[%km_EasymouseWestKey%]
km_EasymouseEastKey := km_IniRead("EasyMouse", "EasymouseEastKey", "")
km_EasymouseNorthKey := km_IniRead("EasyMouse", "EasymouseNorthKey", "")
km_EasymouseSouthKey := km_IniRead("EasyMouse", "EasymouseSouthKey", "")
km_EasymouseWest_fraction := km_IniRead("EasyMouse", "WestFraction", "0.15")
km_EasymouseEast_fraction := km_IniRead("EasyMouse", "EastFraction", "0.85")
km_EasymouseNorth_fraction := km_IniRead("EasyMouse", "NorthFraction", "0.3")
km_EasymouseSouth_fraction := km_IniRead("EasyMouse", "SouthFraction", "0.7")
km_DefineEasymouseLiteHotkeys()
km_isIniLoaded := true
}
km_IniWrite(section, key, value)
{
IniWrite, %value%, %km_cfgfile%, %section%, %key%
if ErrorLevel {
; dev_TooltipAutoClear("km_IniWrite() fail!")
return -1
}
else {
; dev_TooltipAutoClear("km_IniWrite() ok.")
return 0
}
}
km_SaveIni()
{
err = 0
ar_map := ["Left", "Right", "Middle", ""] ; Map radiosel to .action
for index, recname in km_T3recnames
{
radiosel_varname := "km_radiosel_" . recname
strAction := ar_map[%radiosel_varname%]
km_dict_T3obj[recname].action := strAction
err += km_IniWrite("T3keymouse", recname, strAction)
}
err += km_IniWrite("MouseNudge", "isRShiftArrowNudge", km_isRShiftArrowNudge)
err += km_IniWrite("MouseNudge", "RShiftNudgeUnit", km_RShiftNudgeUnit)
err += km_IniWrite("MouseNudge", "isKeypadNudge", km_isKeypadNudge)
err += km_IniWrite("MouseNudge", "KeypadNudgeUnit", km_KeypadNudgeUnit)
err += km_IniWrite("NumpadSpecial", "isNumpadSpecial", km_isNumpadSpecial)
err += km_IniWrite("EasyMouse", "isAppsEasyMouse", km_isAppsEasyMouse)
err += km_IniWrite("EasyMouse", "EasymouseWestKey", km_EasymouseLite_sel2keyname("West"))
err += km_IniWrite("EasyMouse", "EasymouseEastKey", km_EasymouseLite_sel2keyname("East"))
err += km_IniWrite("EasyMouse", "EasymouseNorthKey", km_EasymouseLite_sel2keyname("North"))
err += km_IniWrite("EasyMouse", "EasymouseSouthKey", km_EasymouseLite_sel2keyname("South"))
if(err!=0) {
MsgBox, % msgboxoption_IconExclamation, , % "Unexpected: km_IniWrite() fail on " . km_cfgfile
}
km_DefineEasymouseLiteHotkeys(true, true)
km_isIniLoaded := true
}
km_PromptMissingIni()
{
if(not km_isIniLoaded)
{
km_DoGuiConfig()
; This Gui, on OK Button, will generate the Ini.
}
}
; 2013-08-10 EasyMouse() to position mouse cursor at some proportional position of current active window
; Ref: http://superuser.com/a/14872 (WinGetPos, 'A' on WinGetPos line mean "active window")
; Ref: http://www.autohotkey.com/board/topic/49872-time-precision/ (A_TickCount)
km_EasyMouse(fractionx, fractiony, button="L")
{
WinGetPos, x, y, width, height, A
static mylastx, mylasty, last_tickcount
; MsgBox, get last %mylastx% %mylasty%
mynowx := width*fractionx
mynowy := height*fractiony
If (mynowx==mylastx and mynowy==mylasty and A_TickCount-last_tickcount<1900) {
If (button=="L")
SendInput {Click,Left}
Else
SendInput {Click,Right}
PlaySoundLeftClick()
} else {
MouseMove, mynowx, mynowy
mylastx := mynowx
mylasty := mynowy
last_tickcount := A_TickCount
; MsgBox, Set last %mylastx% %mylasty%
}
}
km_DoGuiConfig()
{
Gui, kmcfg:Destroy ; destroy old
Gui, kmcfg:+HwndKmcfgHwnd ; generate (global?) variable KmcfgHwnd
Gui, kmcfg:Font, s9 cBlack, Tahoma
Gui, kmcfg:Add, Text, , % "Configure Autohotkey keymouse module parameters. Call this dialog again with Ctrl+PrintScreen."
; Gui, kmcfg:Add, Text, , % "" ; make a blank line
Gui, kmcfg:Add, Text, , % "Use the following keys for mouse click:"
for index, recname in km_T3recnames
{
o := km_dict_T3obj[recname]
Gui, kmcfg:Add, Text , xm w120 Section, % kmc_indents . o.friendlyname . " action:"
Gui, kmcfg:Add, Radio, % "ys x+m Group vkm_radiosel_" . recname . km_T3QueryChecked(recname, "Left"), % "Left click"
Gui, kmcfg:Add, Radio, % "ys x+m " . km_T3QueryChecked(recname, "Right"), % "Right click"
Gui, kmcfg:Add, Radio, % "ys x+m " . km_T3QueryChecked(recname, "Middle"), % "Middle click"
Gui, kmcfg:Add, Radio, % "ys x+m " . km_T3QueryChecked(recname, ""), % "None"
}
; Gui, kmcfg:Add, Text, xm , % "" ; blank line, x return to left margin
optchecked := km_isRShiftArrowNudge ? "Checked" : ""
Gui, kmcfg:Add, Checkbox, % kmc_ybiggap . " xm vkm_isRShiftArrowNudge Section " . optchecked
, % "Use &Right-Shift + arrow keys to nudge mouse,"
Gui, kmcfg:Add, Edit, vkm_RShiftNudgeUnit ys-2, %km_RShiftNudgeUnit% ; -2 is arbitrary, just visually better
Gui, kmcfg:Add, Text, ys, % "pixels each time."
;
optchecked := km_isKeypadNudge ? "Checked" : ""
Gui, kmcfg:Add, Checkbox, % "xm vkm_isKeypadNudge Section " . optchecked
, % "Use Numpad keys(when NumLock off) to nudge mouse and do click,"
Gui, kmcfg:Add, Edit, vkm_KeypadNudgeUnit ys-2, %km_KeypadNudgeUnit%
Gui, kmcfg:Add, Text, ys, % "pixels each time."
;
Gui, kmcfg:Add, Checkbox, % "xm vkm_isNumpadSpecial " . (km_isNumpadSpecial ? "Checked" : "")
, % "Us&e Numpad / * - + specially."
; Gui, kmcfg:Add, Text, xm , % "" ; blank line, x return to left margin
optchecked := km_isAppsEasyMouse ? "Checked" : ""
Gui, kmcfg:Add, Checkbox, % "xm vkm_isAppsEasyMouse Section " . kmc_ybiggap . optchecked
, % "Use AppsKey + Numpad(when NumLock off) to do &EasyMouse move && click."
; Gui, kmcfg:Add, Text, xm , % "" ; blank line, x return to left margin
Gui, kmcfg:Add, Text, % "xm " . kmc_ybiggap . " vkmc_EasymouseLiteHint Section" ; Pending! Static Text does not report non-null A_GuiControl in km_WM_MOUSEMOVE()
, % "AppsKey+<key> to do EasyMouse move without Numpad:" ; blank line, x return to left margin
Gui, kmcfg:Add, Edit, % "ys-2 x+m ReadOnly vkmc_EasymouseLiteHint_q", % " (?) " ; use a small editbox as workaround
;
Gui, kmcfg:Add, Text, xm w120 Section vkmc_EasymouseLiteHintW, % kmc_indents . "EasyMouse WEST:"
Gui, kmcfg:Add, Radio, % "ys x+m vkm_EasymouseWest_radiosel Group " . km_EasymouseLiteChecked("West", "SC137"), % "PrintScreen" ;1
Gui, kmcfg:Add, Radio, % "ys x+m " . km_EasymouseLiteChecked("West", "SC046"), % "ScrollLock" ;2
Gui, kmcfg:Add, Radio, % "ys x+m " . km_EasymouseLiteChecked("West", "Pause"), % "Pause" ;3
Gui, kmcfg:Add, Radio, % "ys x+m " . km_EasymouseLiteChecked("West", "PgUp"), % "PageUp " ;4
Gui, kmcfg:Add, Radio, % "ys x+m " . km_EasymouseLiteChecked("West", "Home"), % "Home" ;5
Gui, kmcfg:Add, Radio, % "ys x+m " . km_EasymouseLiteChecked("West", ""), % "None" ;6
Gui, kmcfg:Add, Edit, % "ys-2 x+m vkm_EasymouseWest_fraction ", % km_EasymouseWest_fraction
;
Gui, kmcfg:Add, Text, xm w120 Section vkmc_EasymouseLiteHintE, % kmc_indents . "EasyMouse EAST:"
Gui, kmcfg:Add, Radio, % "ys x+m vkm_EasymouseEast_radiosel Group " . km_EasymouseLiteChecked("East", "SC137"), % "PrintScreen"
Gui, kmcfg:Add, Radio, % "ys x+m " . km_EasymouseLiteChecked("East", "SC046"), % "ScrollLock"
Gui, kmcfg:Add, Radio, % "ys x+m " . km_EasymouseLiteChecked("East", "Pause"), % "Pause"
Gui, kmcfg:Add, Radio, % "ys x+m " . km_EasymouseLiteChecked("East", "PgDn"), % "PageDown"
Gui, kmcfg:Add, Radio, % "ys x+m " . km_EasymouseLiteChecked("East", "End"), % "End"
Gui, kmcfg:Add, Radio, % "ys x+m " . km_EasymouseLiteChecked("East", ""), % "None"
Gui, kmcfg:Add, Edit, % "ys-2 x+m vkm_EasymouseEast_fraction", % km_EasymouseEast_fraction
;
Gui, kmcfg:Add, Text, xm w120 Section vkmc_EasymouseLiteHintN, % kmc_indents . "EasyMouse NORTH:"
Gui, kmcfg:Add, Radio, % "ys x+m vkm_EasymouseNorth_radiosel Group " . km_EasymouseLiteChecked("North", "SC137"), % "PrintScreen"
Gui, kmcfg:Add, Radio, % "ys x+m " . km_EasymouseLiteChecked("North", "SC046"), % "ScrollLock"
Gui, kmcfg:Add, Radio, % "ys x+m " . km_EasymouseLiteChecked("North", "Pause"), % "Pause"
Gui, kmcfg:Add, Radio, % "ys x+m " . km_EasymouseLiteChecked("North", "PgUp"), % "PageUp "
Gui, kmcfg:Add, Radio, % "ys x+m " . km_EasymouseLiteChecked("North", "Home"), % "Home"
Gui, kmcfg:Add, Radio, % "ys x+m " . km_EasymouseLiteChecked("North", ""), % "None"
Gui, kmcfg:Add, Edit, % "ys-2 x+m vkm_EasymouseNorth_fraction ", % km_EasymouseNorth_fraction
;
Gui, kmcfg:Add, Text, xm w120 Section vkmc_EasymouseLiteHintS, % kmc_indents . "EasyMouse SOUTH:"
Gui, kmcfg:Add, Radio, % "ys x+m vkm_EasymouseSouth_radiosel Group " . km_EasymouseLiteChecked("South", "SC137"), % "PrintScreen"
Gui, kmcfg:Add, Radio, % "ys x+m " . km_EasymouseLiteChecked("South", "SC046"), % "ScrollLock"
Gui, kmcfg:Add, Radio, % "ys x+m " . km_EasymouseLiteChecked("South", "Pause"), % "Pause"
Gui, kmcfg:Add, Radio, % "ys x+m " . km_EasymouseLiteChecked("South", "PgDn"), % "PageDown"
Gui, kmcfg:Add, Radio, % "ys x+m " . km_EasymouseLiteChecked("South", "End"), % "End"
Gui, kmcfg:Add, Radio, % "ys x+m " . km_EasymouseLiteChecked("South", ""), % "None"
Gui, kmcfg:Add, Edit, % "ys-2 x+m vkm_EasymouseSouth_fraction ", % km_EasymouseSouth_fraction
Gui, kmcfg:Font, s9 cBlue, Tahoma
Gui, kmcfg:Add, Text, xm, % "NOTE: Answering OK will reload the whole AHK script. (normally nothing harmful)"
Gui, kmcfg:Add, Button, Default Section, OK ; The label ButtonOK (if it exists) will be run when the button is pressed.
Gui, kmcfg:Add, Button, ys x+m , Cancel
Gui, kmcfg:Show
WinSet, AlwaysOnTop, On, ahk_id %KmcfgHwnd%
fn := Func("km_WM_MOUSEMOVE")
OnMessage(0x200, fn) ; new-style, turn a function-name into a function object
; // OnMessage(0x200, "km_WM_MOUSEMOVE") // this is old-style and will not co-exist with other GUI's WM_MOUSEMOVE hook
return
kmcfgButtonOK:
Gui, kmcfg:Submit
km_SaveIni()
Reload
kmcfgGuiClose:
kmcfgGuiEscape:
kmcfgButtonCancel:
OnMessage(0x200, Func("km_WM_MOUSEMOVE"), 0) ; remove our message hook
Gui, kmcfg:Destroy
kmcfgCleanup:
tooltip
return
}
km_DoClick(button)
{
if(not km_isIniLoaded)
return
; button is "Left", "Right" or "Middle"
if(button=="Left") {
SendInput {Click,Left}
PlaySoundLeftClick()
}
else if(button=="Right") {
SendInput {Click,Right}
PlaySoundRightClick()
}
else if(button=="Middle") {
SendInput {Click,Middle}
}
else {
MsgBox, Bad param for km_DoClick(%button%), possibly a bug in %A_ScriptName%
}
}
km_WM_MOUSEMOVE()
{
; dev_TooltipAutoClear("~~~~~~km_WM_MOUSEMOVE() called")
if(A_GuiControl=="km_isKeypadNudge")
{
tooltip, % "When NumLock is off, press Numpad area arrow keys to nudge mouse.`r`n"
. "And even better, use [Numpad /] to simulate LButton pressing down and [Numpad *] to release LButton."
}
else if(A_GuiControl=="km_isNumpadSpecial")
{
tooltip,
(
Use Numpad area keys specially:.
/ to left-click
* to right-click
- to simulate Ctrl+X (cut)
+ to simulate Ctrl+C (copy)
Enter to simulate Ctrl+V (paste)
)
}
else if(A_GuiControl=="km_isAppsEasyMouse")
{
tooltip,
(
When NumLock is off:
Press [App + one of the nine numpad arrow keys] to move mouse pointer at some proportional position of current active window.
First press of the hotkey moves the mouse, a second press of the same hotkey will left-click on that position.
-- This behavior is called EasyMouse.
)
}
else if(StrIsStartsWith(A_GuiControl, "kmc_EasymouseLiteHint"))
{
tooltip,
(
Assign alternate EasyMouse hotkeys, especially when you do not have Numpad(e.g. on many laptop computers).
These hotkeys let you place your mouse pointer at four positions(East/West/North/South) quickly.
What's more, you can customized the four positions' fraction.
)
}
else if(A_Gui=="kmcfg")
{
tooltip
;tooltip , % "A_GuiControl=" . A_GuiControl ; debug
}
}
Km_T3key_do_action(keyname, action)
{
km_PromptMissingIni()
;tooltip, >>>>>>>>>%keyname% do click of %action%
if(action)
km_DoClick(action)
else
Send {%keyname%}
}
km_RShiftNudge_do(arrowname, dx, dy)
{
if(km_isRShiftArrowNudge) {
MouseNudge(dx, dy, km_RShiftNudgeUnit)
}
else {
MsgBox, % "In " . A_ThisFunc . "(), this should not be seen, probably a bug! (ahkname=" . ahkname . ")"
; Send +{%arrowname%}
}
}
km_KeypadNudge_do(ahkname, dx, dy)
{
; Dbgwin_Output(Format("In km_KeypadNudge_do(), dx={} dy={}.", dx, dy)) ; debug
if(km_isKeypadNudge) {
if(ahkname=="NumpadDiv") {
; Dbgwin_Output("Simulate mouse LButton down.") ; debug
Send {LButton down}
dev_TooltipAutoClear("Simulated mouse LButton down.")
}
else if(ahkname=="NumpadMult") {
; Dbgwin_Output("Simulate mouse LButton up.") ; debug
Send {LButton up}
dev_TooltipAutoClear("Simulated mouse LButton up.")
}
else {
MouseNudge(dx, dy, km_KeypadNudgeUnit)
}
}
else {
MsgBox, % "In " . A_ThisFunc . "(), this should not be seen, probably a bug! (ahkname=" . ahkname . ")"
; Send {%ahkname%}
}
}
km_NumpadSpecial_do(ahkname)
{
if(ahkname=="NumpadDiv")
LeftClickWithSound()
else if(ahkname=="NumpadMult")
RightClickAndPlaySound()
else if(ahkname=="NumpadSub")
Send ^x
else if(ahkname=="NumpadAdd")
Send ^c
else if(ahkname=="NumpadIns")
Send ^v
else {
MsgBox, % "In " . A_ThisFunc . "(), this should not be seen, probably a bug! (ahkname=" . ahkname . ")"
}
}
km_EasyMouseNumpad(fractionx, fractiony, button="L")
{
if(km_isAppsEasyMouse)
km_EasyMouse(fractionx, fractiony, button)
}
km_TooltipOff:
tooltip
return
km_RememberPinPos()
{
CoordMode, Mouse, Screen ;sets coordinates based upon screen resolution
MouseGetPos, pinx, piny
CoordMode, Mouse, Relative ;restore coordinates based upon active window
km_PinnedMousePos.x := pinx
km_PinnedMousePos.y := piny
tooltip, % "Mouse position remembered (" . pinx . "," . piny . ")"
SetTimer, km_TooltipOff, -2000
return
}
km_RestorePinPos(speed:=3)
{
; tooltip, 2222222222
CoordMode, Mouse, Screen ;sets coordinates based upon screen resolution
MouseMove, % km_PinnedMousePos.x, % km_PinnedMousePos.y, %speed%
CoordMode, Mouse, Relative ;restore coordinates based upon active window
}
;^SC137:: km_DoGuiConfig() ; Ctrl+PrintScreen
;!#\:: km_DoGuiConfig()
; ^NumLock:: km_RestorePinPos() ; strange! ^NumLock does not response, but +NumLock is ok.
;===========================================================================
; Mouse wiggle.
; Once started, the mouse will wiggle back and forth every one second.
; Purpose: Wiggling your mouse will make Youtube online player keep showing playback progress bar.
;===========================================================================
km_Start_MouseWiggle()
{
dev_TooltipAutoClear("Start mouse wiggle ...")
SetTimer, km_MouseWiggleTimer, 1000
km_MouseWiggleTimer()
}
km_Stop_MouseWiggle()
{
dev_TooltipAutoClear("Stop mouse wiggle.")
SetTimer, km_MouseWiggleTimer, Off
}
km_MouseWiggleTimer()
{
static xoff := -2
xoff := 0 - xoff
MouseMove, xoff, 0, ,R
}
km_menu_ToggleMouseWiggle()
{
static s_prompted := false
static s_on_or_off := false
if(s_on_or_off==false)
{
if(!s_prompted)
{
info =
(
The mouse will wiggle back and forth every one second from now on.
If you want to simulate constant mouse moving activity from a human user, you can use this feature.
You can Start/Stop this behavior from AmHotkey tray menu item.
Note on high-DPI monitor: If you tell Windows to set monitor-DPI-scaling >100`%, this AHK script may position your mouse pointer erroneously. To work around, bring up Property dialog of this exe/lnk -> [Compatibility] -> [High-DPI setting] -> Let this application`(Autohotkey program itself`) scale the UI by itself, instead of by System.
Enable this feature now?
)
is_yes := dev_MsgBoxYesNo_title("Mouse-wiggle feature", info)
if(!is_yes)
return ; do nothing
}
s_prompted := true
s_on_or_off := true
Menu, tray, check, %km_menutext_MouseWiggle%
km_Start_MouseWiggle()
}
else
{
s_on_or_off := false
Menu, tray, uncheck, %km_menutext_MouseWiggle%
km_Stop_MouseWiggle()
}
}
; ============== Final Init ===============
km_AddSystrayMenuItem()
{
Menu, tray, add ; Creates a separator line.
Menu, tray, add, Configure Keymouse, km_DoGuiConfig ; Creates a new menu item.
; ; ;
Menu, tray, add, %km_menutext_MouseWiggle%, km_menu_ToggleMouseWiggle
}