-
Notifications
You must be signed in to change notification settings - Fork 0
/
Xarty-extend-compose-variant.ahk
679 lines (640 loc) · 13.9 KB
/
Xarty-extend-compose-variant.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
#Requires AutoHotkey >= 2
A_MaxHotkeysPerInterval := 150
A_HotkeyInterval := 1000
SetMouseDelay 1
SetDefaultMouseSpeed 2
SetKeyDelay -1
ProcessSetPriority "A"
FileEncoding "UTF-8" ; https://www.autohotkey.com/docs/v2/lib/File.htm#Encoding
; extendKey := "CapsLock"
; extendLayer1Key := "Shift"
; extendLayer2Key := "Ctrl"
intervalAllowedForComposeValidation := 5000,
intervalAllowedForExtendLayerActivation := 150,
timeSinceExtendPrestart := -intervalAllowedForExtendLayerActivation - 1,
modifierHotKey := "",
globalSendMode := "Input"
if FileExist("compose.txt") == ""
{
FileAppend "
(
; This file is used to create compose key pairs
; For details and specification, refer to https://github.com/CarrieForle/xarty/wiki/Xarty-with-AHK#composetxt
=btw=By the way
=name=CarrieForle
=lol=(゚∀。)
)", "compose.txt"
}
wordList := Array(),
wordList.Length := wordList.Capacity := 10
loop wordList.Length
wordList[A_Index] := Map()
Loop Read "compose.txt"
{
if A_LoopReadLine == ""
continue
delimiterChar := SubStr(A_LoopReadLine, 1, 1)
if delimiterChar == ";" ||
delimiterChar == "`n" ||
delimiterChar == A_Tab ||
delimiterChar == A_Space
continue
keypair := StrSplit(A_LoopReadLine, delimiterChar,, 3)
if keypair.Length < 3 || keypair[2] == "" ||keypair[3] == ""
{
if "No" == MsgBox(A_LoopReadLine " is not a valid compose keypair.`n`nClick `"Yes`" to cuntinue and ignore this keypair.`nClick `"No`" to terminate the script.", "Error in compose.txt", 4)
ExitApp
}
else if StrLen(keypair[2]) > 10
{
if "No" == MsgBox(A_LoopReadLine " is too long for a key (> 10).`n`nClick `"Yes`" to cuntinue and ignore this keypair.`nClick `"No`" to terminate the script.", "Error in compose.txt", 4)
ExitApp
}
else
{
wordList[11 - StrLen(keypair[2])].Set(keypair[2], keypair[3])
}
}
VarSetStrCapacity &keypair, 0
if GetKeyState("CapsLock", "T")
SetCapsLockState "AlwaysOn"
else
SetCapsLockState "AlwaysOff"
#InputLevel 1
#HotIf modifierHotKey == "Shift up" && A_TickCount - timeSinceExtendPrestart <= intervalAllowedForExtendLayerActivation
CapsLock::
{
SendEvent("{vk3c DownR}{vk3d Up}{vk3e Up}"),
KeyWait "CapsLock"
}
#HotIf modifierHotKey == "Ctrl up" && A_TickCount - timeSinceExtendPrestart <= intervalAllowedForExtendLayerActivation
CapsLock::
{
SendEvent("{vk3c Up}{vk3d DownR}{vk3e Up}"),
KeyWait "CapsLock"
}
#HotIf !GetKeyState("CapsLock", "P")
~Ctrl up::
~Shift up::
{
global
timeSinceExtendPrestart := A_TickCount,
modifierHotKey := ThisHotKey
}
#HotIf
CapsLock & Shift::
+CapsLock::
{
SendEvent("{vk3c DownR}{vk3d Up}{vk3e Up}"),
KeyWait "CapsLock"
}
CapsLock & Ctrl::
^CapsLock::
{
SendEvent("{vk3c Up}{vk3d DownR}{vk3e Up}"),
KeyWait "CapsLock"
}
^+CapsLock::
~CapsLock::
{
SendEvent("{vk3c Up}{vk3d Up}{vk3e DownR}"),
KeyWait "CapsLock"
}
CapsLock up::
{
SendEvent "{vk3c Up}{vk3d Up}{vk3e Up}"
}
#SuspendExempt
#Hotif A_IsSuspended
CapsLock::CapsLock ; for CapsLock to be toggleable while suspending
#HotIf
RAlt & LAlt::
LAlt & RAlt::Suspend -1
^+sc006::
{
SendEvent("{vk3c Up}{vk3d Up}{vk3e Up}"),
Reload
}
^+sc029::ExitApp
#SuspendExempt false
#InputLevel 0
#HotIf
HoldKey(key) {
SendInput("{Blind}{" key " DownR}"),
KeyWait key, "L"
}
HoldKeyNormal(key) {
SendInput("{Blind}{" key " Down}"),
KeyWait key, "L"
}
vk3c & sc002::!
vk3c & sc003::@
vk3c & sc004::#
vk3c & sc005::$
vk3c & sc006::%
vk3c & sc007::^
vk3c & sc008::Numpad7
vk3c & sc009::Numpad8
vk3c & sc00a::Numpad9
vk3c & sc00b::NumpadMult
vk3c & sc00c::NumpadSub
vk3c & sc00d::=
vk3c & sc010::Home
vk3c & sc011::Up
vk3c & sc012::End
vk3c & sc013::Del
vk3c & sc014::Esc
vk3c & sc015::PgUp
vk3c & sc016::Numpad4
vk3c & sc017::Numpad5
vk3c & sc018::Numpad6
vk3c & sc019::NumpadAdd
vk3c & sc01a::(
vk3c & sc01b::)
vk3c & sc02b::,
vk3c & sc01e::Left
vk3c & sc01f::Down
vk3c & sc020::Right
vk3c & sc021::Backspace
vk3c & sc022::NumLock
vk3c & sc023::PgDn
vk3c & sc024::Numpad1
vk3c & sc025::Numpad2
vk3c & sc026::Numpad3
vk3c & sc027::NumpadEnter
vk3c & sc028::'
;'
vk3c & sc02c::^z
vk3c & sc02d::^x
vk3c & sc02e::^c
vk3c & sc02f::^v
vk3c & sc030::LButton
vk3c & sc031:::
vk3c & sc032::Numpad0
vk3c & sc033::Numpad0
vk3c & sc034::NumpadDot
vk3c & sc035::NumpadDiv
vk3d & sc029::
vk3d & sc002::
vk3d & sc003::
vk3d & sc004::
vk3d & sc005::
vk3d & sc006::
vk3d & sc007::
vk3d & sc008::
vk3d & sc009::
vk3d & sc00a::
vk3d & sc00b::
vk3d & sc00c::
vk3d & sc00d::return
vk3d & sc010::[
vk3d & sc011::]
vk3d & sc012::~
vk3d & sc013::
vk3d & sc014::
vk3d & sc015::return
vk3d & sc016::'
;'
vk3d & sc017::"
;"
vk3d & sc018::\
vk3d & sc019::
vk3d & sc01a::
vk3d & sc01b::
vk3d & sc02b::return
vk3d & sc01e::(
vk3d & sc01f::)
vk3d & sc020::`
vk3d & sc021::
vk3d & sc022::
vk3d & sc023::return
vk3d & sc024::`{
vk3d & sc025::}
vk3d & sc026::%
vk3d & sc027::!
vk3d & sc028::return
vk3d & sc02c::&
vk3d & sc02d::|
vk3d & sc02e::*
vk3d & sc02f::
vk3d & sc030::
vk3d & sc031::return
vk3d & sc032::+
vk3d & sc033::-
vk3d & sc034::=
vk3d & sc035::return
vk3e & Esc::CapsLock
vk3e & F1::HoldKey "Media_Play_Pause"
vk3e & F1 up::Send "{blind}{Media_Play_Pause Up}"
vk3e & F2::HoldKey "Media_Prev"
vk3e & F2 up::Send "{blind}{Media_Prev Up}"
vk3e & F3::HoldKey "Media_Next"
vk3e & F3 up::Send "{blind}{Media_Next Up}"
vk3e & F4::HoldKey "Media_Stop"
vk3e & F4 up::Send "{blind}{Media_Stop Up}"
vk3e & F5::HoldKey "Volume_Mute"
vk3e & F5 up::Send "{blind}{Volume_Mute Up}"
vk3e & F6::Volume_Down
vk3e & F7::Volume_Up
vk3e & F8::HoldKey "Launch_Media"
vk3e & F8 up::Send "{blind}{Launch_Media Up}"
vk3e & sc029::SendEvent "{Click 16 -96 0}"
vk3e & sc002::F1
vk3e & sc003::F2
vk3e & sc004::F3
vk3e & sc005::F4
vk3e & sc006::F5
vk3e & sc007::F6
vk3e & sc008::F7
vk3e & sc009::F8
vk3e & sc00a::F9
vk3e & sc00b::F10
vk3e & sc00c::F11
vk3e & sc00d::F12
vk3e & sc010::Esc
vk3e & sc011::WheelUp
vk3e & sc012::Browser_Back
vk3e & sc013::Browser_Forward
vk3e & sc014::SendInput "{Click 0 -20 0 Rel}"
vk3e & sc015::PgUp
vk3e & sc016::Home
vk3e & sc017::Up
vk3e & sc018::End
vk3e & sc019::Del
vk3e & sc01a::WheelLeft
vk3e & sc01b::WheelRight
vk3e & sc01e::Alt
vk3e & sc01f::WheelDown
vk3e & sc020::Shift
vk3e & sc021::Ctrl
vk3e & sc022::SendInput "{Click 0 20 0 Rel}"
vk3e & sc023::PgDn
vk3e & sc024::Left
vk3e & sc025::Down
vk3e & sc026::Right
vk3e & sc027::BackSpace
vk3e & sc028::HoldKey "AppsKey"
vk3e & sc028 up::Send "{blind}{AppsKey Up}"
vk3e & sc02c::^z
vk3e & sc02d::^x
vk3e & sc02e::^c
vk3e & sc02f::^v
vk3e & sc030::Ins
vk3e & sc031::LButton
vk3e & sc032::MButton
vk3e & sc033::RButton
vk3e & sc034::SendInput "{Click -42 0 0 Rel}"
vk3e & sc035::SendInput "{Click 42 0 0 Rel}"
vk3e & Enter::^BackSpace
vk3e & Space::Enter
; sc029::`
; sc002::1
; sc003::2
; sc004::3
; sc005::4
; sc006::5
; sc007::6
; sc008::7
; sc009::8
; sc00a::9
; sc00b::0
; sc00c::-
; sc00d::=
; sc010::v
; sc011::h
; sc012::s
; sc013::g
; sc014::b
; sc015::j
; sc016::m
; sc017::o
; sc018::u
; sc019::;
; sc01a::[
; sc01b::]
; sc02b::\
; sc01e::x
; sc01f::a
; sc020::r
; sc021::t
; sc022::y
; sc023::k
; sc024::n
; sc025::e
; sc026::i
; sc027::w
; sc028::'
; sc02c::z
; sc02d::f
; sc02e::l
; sc02f::d
; sc030::q
; sc031::c
; sc032::p
; sc033::,
; sc034::.
; sc035::/
*sc029::
{
SendMode(globalSendMode),SetKeyDelay(-1),Send("{Blind}{` DownR}")
}
*sc029 up::Send "{Blind}{` Up}"
*sc002::
{
SendMode(globalSendMode),SetKeyDelay(-1),Send("{Blind}{1 DownR}")
}
*sc002 up::Send "{Blind}{1 Up}"
*sc003::
{
SendMode(globalSendMode),SetKeyDelay(-1),Send("{Blind}{2 DownR}")
}
*sc003 up::Send "{Blind}{2 Up}"
*sc004::
{
SendMode(globalSendMode),SetKeyDelay(-1),Send("{Blind}{3 DownR}")
}
*sc004 up::Send "{Blind}{3 Up}"
*sc005::
{
SendMode(globalSendMode),SetKeyDelay(-1),Send("{Blind}{4 DownR}")
}
*sc005 up::Send "{Blind}{4 Up}"
*sc006::
{
SendMode(globalSendMode),SetKeyDelay(-1),Send("{Blind}{5 DownR}")
}
*sc006 up::Send "{Blind}{5 Up}"
*sc007::
{
SendMode(globalSendMode),SetKeyDelay(-1),Send("{Blind}{6 DownR}")
}
*sc007 up::Send "{Blind}{6 Up}"
*sc008::
{
SendMode(globalSendMode),SetKeyDelay(-1),Send("{Blind}{7 DownR}")
}
*sc008 up::Send "{Blind}{7 Up}"
*sc009::
{
SendMode(globalSendMode),SetKeyDelay(-1),Send("{Blind}{8 DownR}")
}
*sc009 up::Send "{Blind}{8 Up}"
*sc00a::
{
SendMode(globalSendMode),SetKeyDelay(-1),Send("{Blind}{9 DownR}")
}
*sc00a up::Send "{Blind}{9 Up}"
*sc00b::
{
SendMode(globalSendMode),SetKeyDelay(-1),Send("{Blind}{0 DownR}")
}
*sc00b up::Send "{Blind}{0 Up}"
*sc00c::
{
SendMode(globalSendMode),SetKeyDelay(-1),Send("{Blind}{- DownR}")
}
*sc00c up::Send "{Blind}{- Up}"
*sc00d::
{
SendMode(globalSendMode),SetKeyDelay(-1),Send("{Blind}{= DownR}")
}
*sc00d up::Send "{Blind}{= Up}"
*sc010::
{
SendMode(globalSendMode),SetKeyDelay(-1),Send("{Blind}{v DownR}")
}
*sc010 up::Send "{Blind}{v Up}"
*sc011::
{
SendMode(globalSendMode),SetKeyDelay(-1),Send("{Blind}{h DownR}")
}
*sc011 up::Send "{Blind}{h Up}"
*sc012::
{
SendMode(globalSendMode),SetKeyDelay(-1),Send("{Blind}{s DownR}")
}
*sc012 up::Send "{Blind}{s Up}"
*sc013::
{
SendMode(globalSendMode),SetKeyDelay(-1),Send("{Blind}{g DownR}")
}
*sc013 up::Send "{Blind}{g Up}"
*sc014::
{
SendMode(globalSendMode),SetKeyDelay(-1),Send("{Blind}{b DownR}")
}
*sc014 up::Send "{Blind}{b Up}"
*sc015::
{
SendMode(globalSendMode),SetKeyDelay(-1),Send("{Blind}{j DownR}")
}
*sc015 up::Send "{Blind}{j Up}"
*sc016::
{
SendMode(globalSendMode),SetKeyDelay(-1),Send("{Blind}{m DownR}")
}
*sc016 up::Send "{Blind}{m Up}"
*sc017::
{
SendMode(globalSendMode),SetKeyDelay(-1),Send("{Blind}{o DownR}")
}
*sc017 up::Send "{Blind}{o Up}"
*sc018::
{
SendMode(globalSendMode),SetKeyDelay(-1),Send("{Blind}{u DownR}")
}
*sc018 up::Send "{Blind}{u Up}"
*sc019::
{
SendMode(globalSendMode),SetKeyDelay(-1),Send("{Blind}{; DownR}")
}
*sc019 up::Send "{Blind}{; Up}"
*sc01a::
{
SendMode(globalSendMode),SetKeyDelay(-1),Send("{Blind}{[ DownR}")
}
*sc01a up::Send "{Blind}{[ Up}"
*sc01b::
{
SendMode(globalSendMode),SetKeyDelay(-1),Send("{Blind}{] DownR}")
}
*sc01b up::Send "{Blind}{] Up}"
*sc02b::
{
SendMode(globalSendMode),SetKeyDelay(-1),Send("{Blind}{\ DownR}")
}
*sc02b up::Send "{Blind}{\ Up}"
*sc01e::
{
SendMode(globalSendMode),SetKeyDelay(-1),Send("{Blind}{x DownR}")
}
*sc01e up::Send "{Blind}{x Up}"
*sc01f::
{
SendMode(globalSendMode),SetKeyDelay(-1),Send("{Blind}{a DownR}")
}
*sc01f up::Send "{Blind}{a Up}"
*sc020::
{
SendMode(globalSendMode),SetKeyDelay(-1),Send("{Blind}{r DownR}")
}
*sc020 up::Send "{Blind}{r Up}"
*sc021::
{
SendMode(globalSendMode),SetKeyDelay(-1),Send("{Blind}{t DownR}")
}
*sc021 up::Send "{Blind}{t Up}"
*sc022::
{
SendMode(globalSendMode),SetKeyDelay(-1),Send("{Blind}{y DownR}")
}
*sc022 up::Send "{Blind}{y Up}"
*sc023::
{
SendMode(globalSendMode),SetKeyDelay(-1),Send("{Blind}{k DownR}")
}
*sc023 up::Send "{Blind}{k Up}"
*sc024::
{
SendMode(globalSendMode),SetKeyDelay(-1),Send("{Blind}{n DownR}")
}
*sc024 up::Send "{Blind}{n Up}"
*sc025::
{
SendMode(globalSendMode),SetKeyDelay(-1),Send("{Blind}{e DownR}")
}
*sc025 up::Send "{Blind}{e Up}"
*sc026::
{
SendMode(globalSendMode),SetKeyDelay(-1),Send("{Blind}{i DownR}")
}
*sc026 up::Send "{Blind}{i Up}"
*sc027::
{
SendMode(globalSendMode),SetKeyDelay(-1),Send("{Blind}{w DownR}")
}
*sc027 up::Send "{Blind}{w Up}"
*sc028::
{
SendMode(globalSendMode),SetKeyDelay(-1),Send("{Blind}{' DownR}")
}
*sc028 up::Send "{Blind}{' Up}"
*sc02c::
{
SendMode(globalSendMode),SetKeyDelay(-1),Send("{Blind}{z DownR}")
}
*sc02c up::Send "{Blind}{z Up}"
*sc02d::
{
SendMode(globalSendMode),SetKeyDelay(-1),Send("{Blind}{f DownR}")
}
*sc02d up::Send "{Blind}{f Up}"
*sc02e::
{
SendMode(globalSendMode),SetKeyDelay(-1),Send("{Blind}{l DownR}")
}
*sc02e up::Send "{Blind}{l Up}"
*sc02f::
{
SendMode(globalSendMode),SetKeyDelay(-1),Send("{Blind}{d DownR}")
}
*sc02f up::Send "{Blind}{d Up}"
*sc030::
{
SendMode(globalSendMode),SetKeyDelay(-1),Send("{Blind}{q DownR}")
}
*sc030 up::Send "{Blind}{q Up}"
*sc031::
{
SendMode(globalSendMode),SetKeyDelay(-1),Send("{Blind}{c DownR}")
}
*sc031 up::Send "{Blind}{c Up}"
*sc032::
{
SendMode(globalSendMode),SetKeyDelay(-1),Send("{Blind}{p DownR}")
}
*sc032 up::Send "{Blind}{p Up}"
*sc033::
{
SendMode(globalSendMode),SetKeyDelay(-1),Send("{Blind}{, DownR}")
}
*sc033 up::Send "{Blind}{, Up}"
*sc034::
{
SendMode(globalSendMode),SetKeyDelay(-1),Send("{Blind}{. DownR}")
}
*sc034 up::Send "{Blind}{. Up}"
*sc035::
{
SendMode(globalSendMode),SetKeyDelay(-1),Send("{Blind}{/ DownR}")
}
*sc035 up::Send "{Blind}{/ Up}"
ih := InputHook("V L13", "{Left}{Up}{Right}{Down}{Home}{End}{PgUp}{PgDn}")
*RWin::
{
if ih.InProgress
{
onKeyDown(ih, 0x5c, 0x15c)
}
else
{
ih.Start()
global globalSendMode := "Event"
}
}
~Backspace::
~+Backspace::
{
static backspaceCounter := 0
if ih.Input == ""
{
if backspaceCounter > 3
{
ih.Stop(),
backspaceCounter := 0
}
else
{
backspaceCounter++
}
}
}
~!Backspace::
~*^Backspace::
{
ih.Stop()
}
onChar(ih, ch)
{
static helper := () => ih.Stop()
SetTimer helper, intervalAllowedForComposeValidation
}
onKeyDown(ih, vk, sc)
{
globalSendMode := "Input"
if StrLen(ih.Input) <= 10
{
for words in wordList
{
for key, val in words
{
if key == SubStr(ih.Input, -StrLen(key))
{
ih.Stop(),
SendInput("{Backspace " StrLen(key) "}"),
SendText val
if vk != 0x5c
SendInput Format("`{vk{:x}}", vk)
return
}
}
}
}
ih.Stop()
if vk != 0x5c
SendInput Format("`{vk{:x}}", vk)
}
ih.OnChar := onChar,
ih.OnKeyDown := onKeyDown,
ih.KeyOpt("{Enter} ", "ISN")
; ih.OnEnd := (ih) => MsgBox("InputHook end `n" ih.Input "endofline")