-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathahk-us.ahk
991 lines (868 loc) · 24.8 KB
/
ahk-us.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
;-*- coding: utf-8 -*-
;; Ergohotkey
;; A AutopairHotkey script for system-wide ErgoEmacs keybinding
;;
;; Copyright © 2009 Milan Santosi
;; Copyright © 2012 Benjamin Hansen
;; Copyright © 2013, 2014 Matthew Fidler
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see http://www.gnu.org/licenses/
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Global ergonomic editing command shortcuts for
;; use with autohotkey http://www.autohotkey.com/
;; hotkey layout taken from http://xahlee.org/emacs/ergonomic_emacs_keybinding.html
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Changelog:
;; Changlog moved to github.
;; Version 0.9:
;; - Added beginning and end of buffer commands.
;; Version 0.8:
;; - Added BigCtl, key translation and SetMark
;; Version 0.7:
;; - Added Caps lock to Menu in emacs.
;; Version 0.6:
;; - Unified Script, fixed kill-line-backwards
;; Version 0.5:
;; - Made this generated inside of ergoemacs. Malfunctioning kill-line-backwards re-included.
;; Version 0.4:
;; - Fixed a missing colon, that prevents Alt+i to work. Xah Lee
;; Version 0.3:
;; - added a #SingleInstance directive. Xah Lee
;; Version 0.2:
;; - 'Fixed' malfunctioning kill-line-backwards by remapping it to
;; something without a shift modifier. Not very happy about it.
;; - Replaced Send with SendInput
;; - Replaced occurences of DEL with C-x to 'kill' to the clipboard
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
#SingleInstance force
#MaxHotkeysPerInterval 9999
#NoEnv
#InstallKeybdHook
SendMode Input
Process, priority, , High
IniRead ToggleCtrl, ergoemacs-settings.ini,BigCtl, App
IniRead CurrCaps, ergoemacs-settings.ini, Caps, App
IniRead CurrRAlt, ergoemacs-settings.ini, RAlt, App
IniRead CurrLAlt, ergoemacs-settings.ini, LAlt, App
IniRead CurrRAltLAlt, ergoemacs-settings.ini, RAltLAlt, App
IniRead OutlookSave, ergoemacs-settings.ini, Outlook, Save
IniRead EmacsClient, ergoemacs-settings.ini, Emacs, EmacsClient
IniRead OutlookTemplate, ergoemacs-settings.ini, Outlook, Template
LayLst=
VarLst=
CareL = 0
CareV = 0
CareLV = 0
g_MarkSet=
g_LastBol=
g_LastEol=
g_LastBobp=
modifiers=
skipUpDown=
IniRead CurrLayout, ergoemacs-settings.ini, Curr, Layout
If (CurrLayout == "ERROR"){
CurrLayout=us
}
IniRead CurrTheme, ergoemacs-settings.ini, Curr, Theme
If (CurrTheme == "ERROR"){
CurrTheme=standard
}
IniRead CurrTrans, ergoemacs-settings.ini, Curr, Trans
If (CurrTrans == "ERROR"){
CurrTrans=No Translation
}
IniRead CurrTrans2, ergoemacs-settings.ini, Curr, Trans2
If (CurrTrans2 == "ERROR"){
CurrTrans2=No Translation
}
IniRead ExternalClass, ergoemacs.ini,Class,External
If (ExternalClass == "Error"){
ExternalClass=TscShellContainerClass
}
StringSplit, ExternalClassArray, ExternalClass, *
;; Add Translation
Loop, 120 {
; CurLayout -> TransKey
IniRead CurrKey, ergoemacs.ini, %CurrLayout%, %A_Index%
If (CurrTrans == "No Translation"){
objTrans%CurrKey% := CurrKey
} else {
If (CurrKey != ""){
IniRead TransKey, ergoemacs.ini, %CurrTrans%, %A_Index%
objTrans%CurrKey% := TransKey
}
}
; HostLayout -> CurLayout
IniRead CurrKey, ergoemacs.ini, %CurrTrans2%, %A_Index%
If (CurrTrans2 == "No Translation"){
objTrans_%CurrKey% := CurrKey
} else {
If (CurrKey != ""){
IniRead TransKey, ergoemacs.ini, %CurrLayout%, %A_Index%
objTrans_%CurrKey% := TransKey
}
}
}
CurrLayVar= % "[" . CurrLayout . "-" . CurrTheme . "]"
Loop, Read, ergoemacs.ini
{
If (A_LoopReadLine == "[Layouts]"){
CareL = 1
CareV = 0
} Else If (A_LoopReadLine == "[Themes]"){
CareV = 1
CareL = 0
} Else If (CareL == 1 || CareV == 1){
tmp = %A_LoopReadLine%
NextSec := InStr(tmp,"[")
If (NextSec == 1){
CareL = 0
CareV = 0
} else {
NextSec := InStr(tmp,"=")
If (NextSec != 0){
NextSec := SubStr(tmp,1,NextSec-1)
If (CareL == 1){
LayLst = %LayLst%%NextSec%`n
} else {
VarLst = %VarLst%%NextSec%`n
}
}
}
} Else If (A_LoopReadLine == CurrLayVar){
CareLV = 1
} Else If (CareLV == 1){
tmp = %A_LoopReadLine%
NextSec := InStr(tmp,"[")
If (NextSec == 1){
CareLV = 0
} else {
NextSec := InStr(tmp,"=")
If (NextSec != 0){
fn := SubStr(tmp,1,NextSec - 1)
NextSec := SubStr(tmp,NextSec + 1)
objTrans%NextSec% := fn
objTrans_%NextSec% := fn
;;HotKey, %NextSec%, %fn%
}
}
}
}
;; HotKey,(,autopair-paren
; Create Menu
Loop, parse, LayLst, `n
{
Menu, TranslateKey, add, No Translation, TranslateKeyHandler
Menu, TranslateKey2, add, No Translation, TranslateKey2Handler
If (CurrTrans == "No Translation"){
Menu, TranslateKey, Check,No Translation
} else {
Menu, TranslateKey, UnCheck,No Translation
}
If (CurrTrans2 == "No Translation"){
Menu, TranslateKey2, Check,No Translation
} else {
Menu, TranslateKey2, UnCheck,No Translation
}
If (A_LoopField != ""){
Menu, MenuKey, add, %A_LoopField%, MenuKeyHandler
Menu, TranslateKey, add, %A_LoopField%, TranslateKeyHandler
Menu, TranslateKey2, add, %A_LoopField%, TranslateKey2Handler
If (A_LoopField == CurrLayout){
Menu, MenuKey, Check, %A_LoopField%
} else {
Menu, MenuKey, UnCheck, %A_LoopField%
}
If (A_LoopField == CurrTrans){
Menu, TranslateKey, Check, %A_LoopField%
} else {
Menu, TranslateKey, UnCheck, %A_LoopField%
}
If (A_LoopField == CurrTrans2){
Menu, TranslateKey2, Check, %A_LoopField%
} else {
Menu, TranslateKey2, UnCheck, %A_LoopField%
}
}
}
Loop, parse, VarLst, `n
{
If (A_LoopField != ""){
Menu, ThemeKey, add, %A_LoopField%, ThemeKeyHandler
If (A_LoopField == CurrTheme){
Menu, ThemeKey, Check, %A_LoopField%
} else {
Menu, ThemeKey, UnCheck, %A_LoopField%
}
}
}
Menu, Tray, DeleteAll
Menu, Tray, NoStandard
Menu, tray, add, Keyboard Layouts, :MenuKey
Menu, tray, add, Translated Layout, :TranslateKey
Menu, tray, add, Translated Layout (External), :TranslateKey2
Menu, tray, add, Themes, :ThemeKey
Menu, Tray, add
Menu, Caps, add, Caps Lock, ToggleCaps
Menu, Caps, add, Control, ToggleCaps
Menu, Caps, add, Apps Key, ToggleCaps
Menu, Caps, add, F6, ToggleCaps
If (CurrCaps == "Control"){
Menu, Caps, Check, Control
Hotkey, CapsLock, send-ctl
Hotkey, CapsLock Up, send-ctl-up
;Hotkey Up, previous-line
;Capslock::Ctrl
;+Capslock::Capslock
} Else If (CurrCaps == "Apps Key"){
Menu, Caps, Check, Apps Key
Hotkey, CapsLock, send-apps
;Capslock::AppsKey
;+Capslock::Capslock
} Else if (CurrCaps == "F6"){
Menu, Caps, Check, F6
Hotkey CapsLock, send-f6
;Capslock::F6
;+Capslock::Capslock
} Else {
Menu, Caps, Check, Caps Lock
}
Menu, Tray, add, Caps Lock To, :Caps
Menu, RAlt, add, Alt, ToggleRAlt
Menu, RAlt, add, Control, ToggleRAlt
Menu, RAlt, add, Apps Key, ToggleRAlt
Menu, RAlt, add, F6, ToggleRAlt
If (CurrRAlt == "Control"){
Menu, RAlt, Check, Control
Hotkey, RAlt, send-ctl
Hotkey, RAlt Up, send-ctl-up
} Else If (CurrRAlt == "Apps Key"){
Menu, RAlt, Check, Apps Key
Hotkey, RAlt, send-apps
} Else if (CurrRAlt == "F6"){
Menu, RAlt, Check, F6
Hotkey RAlt, send-f6
} Else {
Menu, RAlt, Check, Alt
}
Menu, Tray, add, Right Alt to, :RAlt
; Left Alt
Menu, LAlt, add, Alt, ToggleLAlt
Menu, LAlt, add, Control, ToggleLAlt
Menu, LAlt, add, Apps Key, ToggleLAlt
Menu, LAlt, add, F6, ToggleLAlt
If (CurrLAlt == "Control"){
Menu, LAlt, Check, Control
Hotkey, LAlt, send-ctl
Hotkey, LAlt Up, send-ctl-up
} Else If (CurrLAlt == "Apps Key"){
Menu, LAlt, Check, Apps Key
Hotkey, LAlt, send-apps
} Else if (CurrLAlt == "F6"){
Menu, LAlt, Check, F6
Hotkey LAlt, send-f6
} Else {
Menu, LAlt, Check, Alt
}
Menu, Tray, add, Left Alt to, :LAlt
Menu, RAltLAlt, add, Alt, ToggleRLA
Menu, RAltLAlt, add, Apps Key, ToggleRLA
Menu, RAltLAlt, add, F6, ToggleRLA
If (CurrRAltLAlt == "Apps Key"){
Menu, RAltLAlt, Check, Apps Key
Hotkey, RAlt & LAlt, send-apps
} Else if (CurrRAltLAlt == "F6"){
Menu, RAltLAlt, Check, F6
Hotkey RAlt & LAlt, send-f6
} Else {
Menu, RAltLAlt, Check, Alt
}
Menu, Tray, add, Left & Right Alt to, :RAltLAlt
Menu, Tray, add, Space->Control, ToggleCtrl
If (ToggleCtrl == "1"){
Menu, Tray, Check, Space->Control
}
Menu, tray, add, Exit, Exit
; The amount of milliseconds of holding the spacebar after which a
; space key is no longer returned.
g_TimeOut := 300
; The amount of milliseconds to delay returning a Ctrl key sequence
; that are potentially accidentally hit with the space bar. If the
; space bar comes up during this delay the regular keys will be
; returned instead. Probably rounds to the nearest 10 milliseconds by
; the OS.
g_Delay := 70
g_SpacePressDownTime := false
g_OtherKeyPressed := false
g_MovementKeyPressed := false
g_SkipNextSpace := false
Hotkey Up, previous-line
Hotkey Down, next-line
Hotkey Left, backward-char
Hotkey Right, forward-char
Hotkey Home, move-beginning-of-line
Hotkey End, move-end-of-line
Hotkey PgUp, scroll-down
Hotkey PgDn, scroll-up
Hotkey ^Left, backward-word
Hotkey ^Right, forward-word
allKeysStr := "LButton*RButton*MButton*WheelDown*WheelUp*WheelLeft*WheelRight*XButton1*XButton2*Tab*Enter*Escape*Backspace*Delete*Insert*ScrollLock*CapsLock*NumLock*Numpad0*Numpad1*Numpad2*Numpad3*Numpad4*Numpad5*Numpad6*Numpad7*Numpad8*Numpad9*NumpadDot*NumpadDiv*NumpadMult*NumpadAdd*NumpadSub*NumpadEnter*F1*F2*F3*F4*F5*F6*F7*F8*F9*F10*F11*F12*F13*F14*F15*F16*F17*F18*F19*F20*F21*F22*F23*F24*AppsKey*Browser_Back*Browser_Forward*Browser_Refresh*Browser_Stop*Browser_Search*Browser_Favorites*Browser_Home*Volume_Mute*Volume_Down*Volume_Up*Media_Next*Media_Prev*Media_Stop*Media_Play_Pause*Launch_Mail*Launch_Media*Launch_App1*Launch_App2*Help*Sleep*PrintScreen*CtrlBreak*Pause*Break"
StringSplit, allKeysArray, allKeysStr, *
Loop %allKeysArray0%
{
key := allKeysArray%A_Index%
Hotkey, % "~*"key, ListenForKey
}
; Keys that are possible to accidentally press with the space key
; while typing fast.
keysToDelayStr := "1*2*3*4*5*6*7*8*9*0*q*w*e*r*t*y*u*i*o*p*[*]*\*a*s*d*f*g*h*j*k*l*;*'*z*x*c*v*b*n*m*,*.*/"
StringSplit, keysToDelayArray, keysToDelayStr, *
Loop %keysToDelayArray0%
{
key := keysToDelayArray%A_Index%
Hotkey, % "*"key, DelayKeyOutput
}
ListenForKey:
g_MarkSet=
g_OtherKeyPressed := true
Return
DelayKeyOutput:
Critical
isExternal := IsExternalProgram()
origKey := SubStr(A_ThisHotkey,0)
;; Get Modifiers
modifiers := GetModifiers()
modifiers2 := GetModifiers2()
if (modifiers2 < 9){
timesf := 10
} else {
timesf := 100
}
pressedKey := origKey
;; Translate to the correct layout
transKey := Asc(pressedKey)
if (isExternal == 1){
transKey := Chr(objTrans_%transKey%)
} else {
transKey := Chr(objTrans%transKey%)
}
if (transKey != ""){
pressedKey := transKey
}
;; get goto subroutine.
transKey := Asc(origKey)*timesf+modifiers2
if (isExternal == 1){
transKey := objTrans_%transKey%
} else {
transKey := objTrans%transKey%
}
; Only wait to see if the space comes up if 1) the space bar key is
; down in the first place and 2) it has been held down for less than
; the timeout and 3) another Ctrl key combo hasn't already been
; pressed.
if((g_SpacePressDownTime != false)
&& (GetSpaceBarHoldTime() < g_TimeOut) && !g_OtherKeyPressed)
{
; Do the sleeping of timeout in small increments, that way if the
; the space key is released in the middle we can quit early.
wait_start_time := A_TickCount
while A_TickCount - wait_start_time + 10 < g_Delay
{
Sleep, 10
if(!getKeyState("Space", "P"))
{
; Since space bar was released, remove the Ctrl modifier.
StringReplace, modifiers, modifiers, ^,
; Force space to fire, because its being released could not
; fire during this routine because this thread is critical.
Gosub *Space up
; Stop the space in the event queue from firing since we
; have already fired it manually.
g_SkipNextSpace := True
Break
}
}
}
if (IsLabel(transKey) & !WinActive("ahk_class Emacs") & !IsExternalProgram()){
Goto %transKey%
} Else {
SendInput % modifiers pressedKey
g_MarkSet=
g_LastBol=
g_LastEol=
g_LastBobp=
}
g_OtherKeyPressed := true
Return
*Space::
Critical
; Don't update on OS simulated repeats but only when the user
; actually pressed the key down for the first time
if(g_SpacePressDownTime == false)
{
g_SpacePressDownTime := A_TickCount
g_OtherKeyPressed := false
}
if (ToggleCtrl == "1"){
SendInput {RCtrl down}
}
Return
*Space up::
Critical
if(g_SkipNextSpace)
{
g_SkipNextSpace := false
}
if (ToggleCtrl == "1"){
SendInput {RCtrl up}
}
if(g_OtherKeyPressed == true)
{
g_SpacePressDownTime := false
Return
}
if (GetSpaceBarHoldTime() <= g_TimeOut)
{
modifiers := GetModifiers()
if (WinActive("ahk_class Emacs") | IsExternalProgram()) {
SendInput % modifiers "{Space}"
} else {
If (modifiers == "!"){
If (g_MarkSet == ""){
g_MarkSet=1
} Else {
g_MarkSet=
g_LastBol=
g_LastEol=
g_LastBobp=
}
} else {
SendInput % modifiers "{Space}"
}
}
}
g_SpacePressDownTime := false
Return
ToggleCtrl:
If (ToggleCtrl == "1"){
IniWrite,0,ergoemacs-settings.ini,BigCtl,App
} Else {
IniWrite,1,ergoemacs-settings.ini,BigCtl,App
}
Reload
return
ToggleRAlt:
IniWrite, %A_ThisMenuItem%,ergoemacs-settings.ini,RAlt,App
Reload
return
ToggleLAlt:
IniWrite, %A_ThisMenuItem%,ergoemacs-settings.ini,LAlt,App
Reload
return
ToggleRLA:
IniWrite, %A_ThisMenuItem%,ergoemacs-settings.ini,RAltLAlt,App
Reload
return
ToggleCaps:
IniWrite, %A_ThisMenuItem%,ergoemacs-settings.ini,Caps,App
Reload
return
ThemeKeyHandler:
IniWrite,%A_ThisMenuItem%,ergoemacs-settings.ini,Curr,Theme
Reload
return
TranslateKeyHandler:
IniWrite, %A_ThisMenuItem%,ergoemacs-settings.ini,Curr,Trans
Reload
return
TranslateKey2Handler:
IniWrite, %A_ThisMenuItem%,ergoemacs-settings.ini,Curr,Trans2
Reload
return
MenuKeyHandler:
IniWrite,%A_ThisMenuItem%,ergoemacs-settings.ini,Curr,Layout
Reload
return
Exit:
ExitApp
return
previous-line:
SendKey("{Up}",1)
return
next-line:
SendKey("{Down}",1)
return
backward-char:
SendKey("{Left}",1)
return
forward-char:
SendKey("{Right}",1)
return
backward-word:
SendKey("{Ctrl down}{Left}{Ctrl up}",1)
return
forward-word:
SendKey("{Ctrl down}{Right}{Ctrl up}",1)
return
move-beginning-of-line:
SendKey("{Home}",1)
return
ergoemacs-end-of-line-or-what:
if (g_LastEol <> ""){
;; Last Key was end of line
;; Send PgDown...
SendKey("{PgDown}",1)
} else {
;; Last key was not bol send home
SendKey("{End}",1)
}
g_LastEol=eol
return
ergoemacs-beginning-of-line-or-what:
if (g_LastBol <> ""){
;; Last Key was beginning of line
;; Send PgUp...
SendKey("{PgUp}",1)
} else {
;; Last key was not bol send home
SendKey("{Home}",1)
}
g_LastBol=bol
return
ergoemacs-end-of-line-or-block:
move-end-of-line:
SendKey("{End}",1)
return
beginning-of-buffer:
SendKey("{Ctrl down}{Home}{Ctrl up}",1)
return
end-of-buffer:
SendKey("{Ctrl down}{End}{Ctrl up}",1)
return
delete-backward-char:
SendKey("{Backspace}",0)
return
delete-char:
SendKey("{Delete}",0)
return
scroll-down:
SendKey("{PgUp}",1)
return
scroll-up:
SendKey("{PgDn}",1)
return
isearch-forward:
SendKey("{Ctrl down}{f}{Ctrl Up}",0)
return
query-replace:
SendKey("{Ctrl down}{h}{Ctrl Up}",0)
return
backward-kill-word:
SendKey("{Shift down}{Ctrl down}{Left}{Ctrl up}{Shift up}{Ctrl down}{x}{Ctrl up}",0)
return
kill-word:
SendKey("{Ctrl down}{Shift down}{Right}{Ctrl up}{Shift up}{Ctrl down}{x}{Ctrl up}",0)
return
kill-line:
SendKey("{Shift down}{End}{Shift up}{Ctrl down}{x}{Ctrl up}",0)
return
ergoemacs-kill-line-backward:
SendKey("{Shift down}{Home}{Shift up}{Ctrl down}{x}{Ctrl up}",0)
return
ergoemacs-beginning-or-end-of-buffer:
if (g_LastBobp <> ""){
;; Last Key was not beginning of buffer
SendKey("{Ctrl down}{Home}{Ctrl up}",1)
g_LastBobp=yes
} else {
;; Last Key was end of buffer
SendKey("{End}",1)
g_LastBobp=
}
return
ergoemacs-cut-line-or-region:
lastClip = %clipboard%
SendKey("{Ctrl down}{x}{Ctrl up}",0)
thisClip = %clipboard%
if (thisClip == lastClip){
SendKey("{Home}{Shift down}{End}{Shift up}{Ctrl down}{x}{Ctrl up}",0)
clipboard = %lastClip%%clipboard%
}
return
ergoemacs-copy-line-or-region:
lastClip = %clipboard%
SendKey("{Ctrl down}{c}{Ctrl up}",0)
thisClip = %clipboard%
if (thisClip == lastClip){
SendKey("{Home}{Shift down}{End}{Shift up}{Ctrl down}{c}{Ctrl up}",0)
}
return
ergoemacs-paste:
yank:
SendKey("{Ctrl down}{v}{Ctrl up}",0)
return
undo:
SendKey("{Ctrl down}{z}{Ctrl up}",0)
return
redo:
SendKey("{Ctrl down}{y}{Ctrl up}",0)
return
execute-extended-command:
;; Send to org-outlook if using outlook
If (!WinActive("ahk_class Emacs") & !IsExternalProgram()){
If WinActive("ahk_class rctrl_renwnd32"){
If !FileExist(OutlookSave){
FileSelectFolder, OutlookSave, ,3, Select Folder to Save Outlook Emails
IniWrite, %OutlookSave%, ergoemacs-settings.ini, Outlook, Save
}
If !FileExist(EmacsClient){
FileSelectFile, EmacsClient, 1, , Emacs Client, Emacs Client (emacs*.exe)
IniWrite, %EmacsClient%, ergoemacs-settings.ini, Emacs, EmacsClient
}
If (OutlookTemplate == "ERROR") {
InputBox OutlookTemplate, Org-mode capture template for emails (can't be blank)
IniWrite, %OutlookTemplate%, ergoemacs-settings.ini, Outlook, Template
}
Clipboard=
SendKey("{Ctrl down}{c}{Ctrl up}")
ClipWait
EmailBody=%clipboard%
EmailBody:=uri_encode(EmailBody)
SendKey("{F12}",0)
Clipboard=
While !WinActive("Save As"){
Sleep 100
}
SendKey("{Ctrl down}{c}{Ctrl up}")
ClipWait
Counter = 1
Title=%clipboard%
Title := uri_encode(Title)
fileName = %OutlookSave%\%clipboard%-%Counter%.msg
while FileExist(fileName)
{
Counter := Counter + 1
fileName = %OutlookSave%\%clipboard%-%Counter%.msg
}
Clipboard =
Clipboard := fileName
ClipWait
While !WinActive("Save As"){
Sleep 100
}
SendKey("{Backspace}")
SendInput, %Clipboard%
SendKey("{Enter}")
While WinActive("Save As"){
Sleep 100
}
SendKey("{Del}")
ocalName = %OutlookSave%\ocal.ics
If !FileExist(ocalName){
Clipboard =
Clipboard := ocalName
ClipWait
Send, {CTRLDOWN}2{CTRLUP}
Send, {ALTDOWN}{ALTUP}fc
While !WinActive("Save As"){
Sleep 100
}
Send, {CTRLDOWN}v{CTRLUP}{TAB 2}{SPACE}{DOWN 3}{TAB}{DOWN 2}{TAB}{SPACE}{DOWN}{SPACE}{TAB 2}{SPACE}{TAB 3}{ENTER}
While WinActive("Save As"){
Sleep 100
}
Send, {CTRLDOWN}1{CTRLUP}
}
fileName := uri_encode(fileName)
fileName = "%EmacsClient%" org-protocol:/capture:/%OutlookTemplate%/%fileName%/%Title%/%EmailBody%
Run, %fileName%
}
}
return
comment-dwim:
;; Word Alt+Ctrl+M is insert comment
If WinActive("ahk_class OpusApp"){
SendKey("{Alt down}{Ctrl down}{M}{Alt up}{Ctrl up}",0)
}
return
ergoemacs-toggle-letter-case:
;; Word Shift+F3 is toggle letter case.
;; Maybe do somthing different in other apps.
If WinActive("ahk_class OpusApp"){
SendKey("{Shift down}{F3}{Shift up}",0)
}
return
split-window-below:
;; Word is Alt+Ctrl+s
If WinActive("ahk_class OpusApp"){
SendKey("{Alt down}{Ctrl down}{s}{Ctrl up}{Alt up}{Enter}",0)
}
return
delete-other-windows:
;; Word is
If WinActive("ahk_class OpusApp"){
SendKey("{Alt down}{Ctrl down}{s}{Alt up}{Ctrl up}",0)
}
return
ergoemacs-move-cursor-next-pane:
;; Word is
If WinActive("ahk_class OpusApp"){
SendKey("{F6}")
}
return
send-ctl:
SendKey("{Ctrl down}")
return
send-ctl-up:
SendKey("{Ctrl up}")
return
send-apps:
SendKey("{AppsKey}")
return
send-f6:
SendKey("{F6}")
return
IsExternalProgram(){
External = 0
if (WinActive("ahk_class TscShellContainerClass")){
External = 1
} else if (WinActive("ahk_class cygwin/x X rl")){
External = 1
} else if (WinActive("ahk_class cygwin/xfree86 rl")){
External = 1
} else if (WinActive("ahk_class Transparent Windows Client")){
External = 1
} else if (WinActive("ahk_class QWidget")){
External = 1
}
Return External
}
GetSpaceBarHoldTime()
{
global g_SpacePressDownTime
time_elapsed := A_TickCount - g_SpacePressDownTime
Return time_elapsed
}
GetModifiers2(){
;; Return the hotkey modifiers that are defined in the ergoemacs.ini
Modifiers = 0
GetKeyState, state1, LWin
GetKeyState, state2, RWin
state = %state1%%state2%
if state <> UU ; At least one Windows key is down.
Modifiers := Modifiers + 1
GetKeyState, state1, Alt
if state1 = D
Modifiers := Modifiers + 2
GetKeyState, state1, Control
if state1 = D
Modifiers := Modifiers + 4
;;GetKeyState, state1, Alt
GetKeyState, state1, LShift
GetKeyState, state2, RShift
state=%state1%%state2%
if state <> UU
Modifiers := Modifiers + 8
Return Modifiers
}
; Return the hotkey symbols (ie !, #, ^ and +) for the modifiers that
; are currently activated
GetModifiers()
{
Modifiers =
GetKeyState, state1, LWin
GetKeyState, state2, RWin
state = %state1%%state2%
if state <> UU ; At least one Windows key is down.
Modifiers = %Modifiers%#
GetKeyState, state1, Alt
if state1 = D
Modifiers = %Modifiers%!
GetKeyState, state1, Control
if state1 = D
Modifiers = %Modifiers%^
;;GetKeyState, state1, Alt
GetKeyState, state1, LShift
GetKeyState, state2, RShift
state = %state1%%state2%
if state <> UU ; At least one shift key is down
Modifiers = %Modifiers%+
Return Modifiers
}
SendKey(key,Movement = 0){
global g_MarkSet
global g_OtherKeyPressed
global g_LastBol
global g_LastEol
g_LastEol=
g_LastBol=
g_OtherKeyPressed := true
If (Movement == 0){
g_MarkSet=
SendInput % key
} Else {
If (g_MarkSet == ""){
SendInput % key
} Else {
SendInput % "{Shift down}" key "{Shift up}"
}
}
}
;functions starts
uri_encode(Unicode_string)
{
;converts unicode_string to uri enocoded string for autohotkey_l unicode version
;http://www.autohotkey.com/forum/viewtopic.php?t=71619
UTF16 := Unicode_string
n := StrPutVar(UTF16, UTF8, "UTF-8")
raw_hex := MCode_Bin2Hex(&UTF8, n-1)
i := strlen(raw_hex)/2
loop, %i%
{
frag := "%" . substr(raw_hex, a_index*2-1,2)
r_s .= frag
}
return r_s
}
MCode_Bin2Hex(addr, len) {
Static fun
If (fun = "") {
If Not A_IsUnicode
h=
( LTrim Join
8B54240C85D2568B7424087E3A53578B7C24148A07478AC8C0E90480F9090F97C3F6
DB80E30702D980C330240F881E463C090F97C1F6D980E10702C880C130880E464A75
CE5F5BC606005EC3
)
Else
h=
( LTrim Join
8B44240C8B4C240485C07E53568B74240C578BF88A168AC2C0E804463C090FB6C076
066683C037EB046683C03066890180E20F83C10280FA09760C0FB6D26683C2376689
11EB0A0FB6C26683C03066890183C1024F75BD33D25F6689115EC333C0668901C3
)
VarSetCapacity(fun, n := StrLen(h)//2)
Loop % n
NumPut("0x" . SubStr(h, 2 * A_Index - 1, 2), fun, A_Index - 1, "Char")
}
VarSetCapacity(hex, A_IsUnicode ? 4 * len + 2 : 2 * len + 1)
DllCall(&fun, "uint", &hex, "uint", addr, "uint", len, "cdecl")
VarSetCapacity(hex, -1) ;update StrLen
Return hex
}
StrPutVar(string, ByRef var, encoding)
{
VarSetCapacity( var, StrPut(string, encoding)
* ((encoding="utf-16"||encoding="cp1200") ? 2 : 1) )
return StrPut(string, &var, encoding)
}