-
Notifications
You must be signed in to change notification settings - Fork 0
/
CapShift.ahk
617 lines (559 loc) · 15.4 KB
/
CapShift.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
; Slows down and extends the capslock and numlock keys.
; Original programming by skrommel with modifications by evl k.freeman and nascent
; Code for Sentence case borrowed from JDN and ManaUser.
#NoTrayIcon
#singleinstance force
;#Persistent
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
iniRead, toggleInsert, CAPShift.ini, Settings, toggleInsert, true
iniRead, toggleNumLock, CAPShift.ini, Settings, toggleNumLock, true
iniRead, TimeLockToggle, CAPShift.ini, Settings, TimeLockToggle, 400
iniRead, TimeOut, CAPShift.ini, Settings, TimeOut, 1000
iniRead, ToggleCaps, CAPShift.ini, Settings, ToggleCaps, false
iniRead, progressBar, CAPShift.ini, Settings, progressBar, true
iniRead, lockColor, CAPShift.ini, Settings, lockColor, 00a300
iniRead, menuColor, CAPShift.ini, Settings, menuColor, 3d3d3d
iniRead, enableTooltips, CAPShift.ini, Settings, enableTooltips, true
iniRead, menuOnly, CAPShift.ini, Settings, menuOnly, false
iniRead, soundBeeps, CAPShift.ini, Settings, soundBeeps, false
;Convert string to boolean as autohotkey sucks at interpreting booleans from iniRead
if (toggleInsert = "true") {
toggleInsert := True
}
else if (toggleInsert = "False") {
toggleInsert := False
}
if (toggleNumLock = "true") {
toggleNumLock := True
}
else if (toggleNumLock = "False") {
toggleNumLock := False
}
if (ToggleCaps = "true") {
ToggleCaps := True
}
else if (ToggleCaps = "False") {
ToggleCaps := False
}
if (progressBar = "true") {
progressBar := True
}
else if (progressBar = "False") {
progressBar := False
}
if (enableTooltips = "true") {
enableTooltips := True
}
else if (enableTooltips = "False") {
enableTooltips := False
}
if (menuOnly = "true") {
menuOnly := True
}
else if (menuOnly = "False") {
menuOnly := False
}
if (soundBeeps = "true") {
soundBeeps := True
}
else if (soundBeeps = "False") {
soundBeeps := False
}
;Initialise tooltips with a default timer value
SetTimer,TOOLTIP,1500
SetTimer,TOOLTIP,Off
ToggleTimer := (TimeLockToggle//10)
MenuTimer := (TimeOut//10)
About =
(LTrim0
CAPShift 3.0
Enhance and stickify the capslock, numlock and insert keys.
Hold for %TimeLockToggle% ms to toggle capslock/numlock/insert on or off.
(Note: Insert Lock is per app not a global state)
Hold for %TimeOut% ms to show a menu that converts selected text to
UPPER CASE, lower case, Title Case, iNVERT cASE, etc
Written by skrommel, evl, k.freeman and nascent
)
*Insert::
*NumpadIns::
if (NOT toggleInsert = "true") {
Gosub, Insert_State_Toggle
return
}
if (menuOnly = "true")
GoSub, MENU
counter=0
if (progressBar = "true"){
Progress, ZH16 ZX0 ZY0 B R0-%MenuTimer% CB%lockColor%
}
Loop, %MenuTimer%
{
Sleep,10
counter+=1
if (progressBar = "true"){
Progress, %counter% ;, SubText, MainText, WinTitle, FontName
}
If (counter = ToggleTimer)
if (progressBar = "true"){
Progress, ZH16 ZX0 ZY0 B R0-%MenuTimer% CB%menuColor%
}
GetKeyState,state,Insert,P
if state=U
Break
}
if (progressBar = "true"){
Progress, Off
}
If counter=%MenuTimer%
Gosub,MENU
Else If (counter>ToggleTimer)
Gosub, Insert_State_Toggle
Return
*CapsLock::
if (menuOnly = "true")
GoSub, MENU
counter=0
if (progressBar = "true"){
Progress, ZH16 ZX0 ZY0 B R0-%MenuTimer% CB%lockColor%
}
Loop, %MenuTimer%
{
Sleep,10
counter+=1
if (progressBar = "true"){
Progress, %counter% ;, SubText, MainText, WinTitle, FontName
}
If (counter = ToggleTimer)
if (progressBar = "true"){
Progress, ZH16 ZX0 ZY0 B R0-%MenuTimer% CB%menuColor%
}
GetKeyState,state,CapsLock,P
if state=U
Break
}
if (progressBar = "true"){
Progress, Off
}
If counter=%MenuTimer%
Gosub,MENU
Else If (counter>ToggleTimer)
Gosub, CapsLock_State_Toggle
Return
*NumLock::
if (NOT toggleNumLock = "true") {
Gosub, NumLock_State_Toggle
return
}
if (menuOnly = "true")
GoSub, MENU
counter=0
if (progressBar = "true"){
Progress, ZH16 ZX0 ZY0 B R0-%MenuTimer% CB%lockColor%
}
Loop, %MenuTimer%
{
Sleep,10
counter+=1
if (progressBar = "true"){
Progress, %counter% ;, SubText, MainText, WinTitle, FontName
}
If (counter = ToggleTimer)
if (progressBar = "true"){
Progress, ZH16 ZX0 ZY0 B R0-%MenuTimer% CB%menuColor%
}
GetKeyState,state,NumLock,P
if state=U
Break
}
if (progressBar = "true"){
Progress, Off
}
If counter=%MenuTimer%
Gosub,MENU
Else If (counter>ToggleTimer)
Gosub, NumLock_State_Toggle
Return
MENU:
Winget, Active_Window, ID, A
Send,^c
ClipWait,20
Menu,main,Add
Menu,main,Delete
Menu,main,Add,CAPShift, EMPTY
Menu,main,Add,
if (ToggleCaps = "true")
{
Menu,main,Add,&CapsLock Toggle,CapsLock_State_Toggle
}
else
{
Menu,main,Add,&CapsLock On,CapsLock_On
Menu,main,Add,CapsL&ock Off,CapsLock_Off
}
if (toggleNumLock = "true")
{
Menu,main,Add,&NumLock Toggle,NumLock_State_Toggle
}
else
{
Menu,main,Add,
Menu,main,Add,&NumLock On,NumLock_On
Menu,main,Add,N&umLock Off,NumLock_Off
}
if (toggleInsert = "true")
{
Menu,main,Add,&Insert Toggle,Insert_State_Toggle
}
else
{
Menu,main,Add,
Menu,main,Add,&NumLock On,NumLock_On
Menu,main,Add,N&umLock Off,NumLock_Off
}
Menu,main,Add,
Menu,settings,Add,&Sticky Numlock,MNUMBERLOCK
Menu,settings,Add,Sticky &Insert,MINSERT
Menu,settings,Add,&Lock Keys Trigger Immediate Menu,MDIRECT
Menu,settings,Add,&Toggle Timer,TTIMER
Menu,settings,Add,&Menu Timer, MTIMER
Menu,settings,Add,Toggle M&enu Item, MTOGGLE
Menu,settings,Add,Toggle P&rogress Bar, MPROGRESS
Menu,settings,Add,Toggle Tooltips, MTOOLTIPS
Menu,settings,Add,Change Pro&gress Bar Color, MlockColor
Menu,settings,Add,Change Menu Progress Bar &Color, MMENUCOLOR
Menu,settings,Add,&Beeps When toggling lock state, MSOUNDBEEP
Menu,convert,Add,&UPPER CASE,MENU_ACTION
Menu,convert,Add,&lower case,MENU_ACTION
Menu,convert,Add,&Sentence case,MENU_ACTION
Menu,convert,Add,&Title Case,MENU_ACTION
Menu,convert,Add,&Smart Title Case,MENU_ACTION
Menu,convert,Add,&iNVERT cASE,MENU_ACTION
;Menu,convert,Add,
Menu,convert,Add,Remove_illegal_characters,MENU_ACTION
Menu,convert,Add,Remove_&under_scores,MENU_ACTION
Menu,convert,Add,Remove.&full.stops,MENU_ACTION
Menu,main,Add,Con&vert Text, :convert
Menu,main,Add,&Settings, :settings
Menu,main,Default,CAPShift
Menu,main,Add,
Menu,main,Add,&About,ABOUT
Menu,main,Add,&Quit,QUIT
Menu,main,Show
Return
MENU_ACTION:
AutoTrim,Off
string=%clipboard%
clipboard:=Menu_Action(A_ThisMenuItem, string)
WinActivate, ahk_id %Active_Window%
Send,^v
string=%tooltiptext%
stringReplace,tooltiptext,A_ThisMenuItem ,% chr(38),,A ;get rid of ampersand
tooltiptext = Selection converted to %tooltiptext%
iniRead, enableTooltips, CAPShift.ini, Settings, enableTooltips, true
if (NOT enableTooltips = "true"){
tooltiptext := ""
}
ToolTip,%tooltiptext%
SetTimer,TOOLTIP,On
Return
Menu_Action(ThisMenuItem, string)
{
Needle =
(join ltrim comments
(^|[.!?:;])\W*\K(([A-Z]{2,4})\b ; first (in the sentence) acronym (upper case $U3)
|([\w']+)) ; any other first word (title case $T4)
|\b(?i)(a|about|above|across|after|against|along|amid|among|amongst|an|and|around|as|at|athwart|atop|barring|before|behind|below|beneath|beside|besides|between|beyond|but|by|circa|concerning|despite|down|during|except|excluding|following|for|from
|in|including|inside|into|like|minus|near|nor|notwithstanding|of|off|on|onto|opposite|or|out|outside|over|past|plus|regarding|s|save|since|so|the|than|through|till|to|toward|towards|under|underneath|unlike|until|up|upon|verus|via|with|within|without|yet)\b ; not first small words (lower case $L5)
|\b(?-i)([A-Z]{2,4})\b ; not first acronym (upper case $U6)
|\b([\w']+) ; any other word (title case $T7)
)
If ThisMenuItem =&UPPER CASE
StringUpper,string,string
Else If ThisMenuItem =&lower case
StringLower,string,string
Else if ThisMenuItem =&Sentence case
{
StringLower, string, string
string := RegExReplace(string, "(((^|([.!?]\s+))[a-z])| i | i')", "$u1")
}
Else If ThisMenuItem =&Title Case
StringLower,string,string,T
Else If ThisMenuItem =&Smart Title Case
{
;StringLower, string, string ;this would negate the Acronym check of Needle, but if text is frequently all uppercase before invoking this method, you might want to normalise text to lowercase first
string := RegExReplace(string,Needle,"$U3$T4$L5$U6$T7")
}
Else If ThisMenuItem =&iNVERT cASE
{
StringCaseSense,On
lower=abcdefghijklmnopqrstuvwxyz
upper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
StringLen,length,string
Loop,%length%
{
StringLeft,char,string,1
StringGetPos,pos,lower,%char%
pos+=1
If pos<>0
StringMid,char,upper,%pos%,1
Else
{
StringGetPos,pos,upper,%char%
pos+=1
If pos<>0
StringMid,char,lower,%pos%,1
}
StringTrimLeft,string,string,1
string.=char
}
StringCaseSense,Off
}
Else If ThisMenuItem =Remove_Illegal_characters
{
StringLower, string, string
;string := RegExReplace(string, "(((^|([.!?]\s+))[a-z])| i | i')", "$u1")
string := RegExReplace(string, "[/\\?%*:|<>]", "$u1")
}
Else If ThisMenuItem =Remove_&under_scores
StringReplace, string, string,_,%A_Space%, All
Else If ThisMenuItem =Remove.&full.stops
StringReplace, string, string,.,%A_Space%, All
Return string
}
EMPTY:
Return
;Hides the tooltip after 1 1/2 seconds
TOOLTIP:
ToolTip,
SetTimer,TOOLTIP,Off
Return
CapsLock_State_Toggle:
If GetKeyState("CapsLock","T")
state=Off
Else
state=On
CapsLock_State_Toggle(state)
Return
CapsLock_State_Toggle(State)
{
tooltiptext = CapsLock %State%
SetCapsLockState,%State%
iniRead, soundBeeps, CAPShift.ini, Settings, soundBeeps, false
if (soundBeeps = "true"){
SoundBeep
}
iniRead, enableTooltips, CAPShift.ini, Settings, enableTooltips, true
if (NOT enableTooltips = "true"){
tooltiptext := ""
}
ToolTip,%tooltiptext%
SetTimer,TOOLTIP,On
}
CapsLock_On:
state=On
CapsLock_State_Toggle(state)
Return
CapsLock_Off:
state=Off
CapsLock_State_Toggle(state)
Return
NumLock_State_Toggle:
If GetKeyState("NumLock","T")
state=Off
Else
state=On
NumLock_State_Toggle(state)
Return
NumLock_State_Toggle(State)
{
iniRead, toggleNumLock, CAPShift.ini, Settings, toggleNumLock, true
SetNumLockState,%State%
if (toggleNumLock = "true") {
iniRead, soundBeeps, CAPShift.ini, Settings, soundBeeps, false
if (soundBeeps = "true"){
SoundBeep
}
iniRead, enableTooltips, CAPShift.ini, Settings, enableTooltips, true
if (enableTooltips = "true"){
tooltiptext = NumLock %State%
ToolTip,%tooltiptext%
SetTimer,TOOLTIP,On
}
}
}
NumLock_On:
state=On
NumLock_State_Toggle(state)
Return
NumLock_Off:
state=Off
NumLock_State_Toggle(state)
Return
Insert_State_Toggle:
If GetKeyState("Insert","T")
state=off
Else
state=On
Insert_State_Toggle(state)
Return
Insert_State_Toggle(State)
{
iniRead, toggleInsert, CAPShift.ini, Settings, toggleInsert, true
;SetInsertState,%State%
Send {INSERT}
if (toggleInsert = "true") {
iniRead, soundBeeps, CAPShift.ini, Settings, soundBeeps, false
if (soundBeeps = "true"){
SoundBeep
}
iniRead, enableTooltips, CAPShift.ini, Settings, enableTooltips, true
if (enableTooltips = "true"){
tooltiptext = Insert %State%
ToolTip,%tooltiptext%
SetTimer,TOOLTIP,On
}
}
}
Insert_On:
state=On
Insert_State_Toggle(state)
Return
Insert_Off:
state=Off
Insert_State_Toggle(state)
Return
MlockColor:
inputBox, TCCOLOR, CAPShift: Progress Bar Color, Enter the desired color wanted for the capslock/numlock progress bar`n(RGB format example: FF0000 is Red),,,,,,,,%lockColor%
if TCCOLOR !=
{
iniWrite, %TCCOLOR%, CAPShift.ini, Settings, lockColor
sleep 100
reload
}
return
MMENUCOLOR:
inputBox, TMCOLOR, CAPShift: Menu Progress Color, Enter the desired color wanted for the menu progress bar`n(RGB format example: FF0000 is Red),,,,,,,,%menuColor%
if TMCOLOR !=
{
iniWrite, %TMCOLOR%, CAPShift.ini, Settings, menuColor
sleep 100
reload
}
return
MSOUNDBEEP:
Menu,settings,Add,&Beeps When toggling lock state, MSOUNDBEEP
MsgBox, 4, CAPShift: Sound Beeps, Select Yes if you want Beeps everytime you toggle Lock State or No for silent operation
IfMsgBox Yes
{
iniWrite, true, CAPShift.ini, Settings, soundBeeps
}
else IfMsgBox No
{
iniWrite, false, CAPShift.ini, Settings, soundBeeps
}
sleep 100
reload
return
MDIRECT:
MsgBox, 4, CAPShift: Immediate Menu, Select Yes if you want Lock Keys to trigger immediate menu on keypress (losing typical key functionality), or No for holding key for sticky capslock/numlock and holding longer for menu.
IfMsgBox Yes
{
iniWrite, true, CAPShift.ini, Settings, menuOnly
}
else IfMsgBox No
{
iniWrite, false, CAPShift.ini, Settings, menuOnly
}
sleep 100
reload
return
TTIMER:
inputBox, TTIME, CAPShift: Timer, Enter the amount of time you want to press the key to toggle CapsLock on/off (1000 = 1 second),, 320, 140
if TTIME !=
{
iniWrite, %TTIME%, CAPShift.ini, Settings, TimeLockToggle
sleep 100
reload
}
return
MTIMER:
inputBox, MTIME, CAPShift: Timer, Enter the amount of time (in milliseconds) you want to press the key to bring up the CAPShift Menu`n(1000 MS = 1 second)`n(Note: rounded to nearest 10ms),, 340, 180
if MTIME !=
{
iniWrite, %MTIME%, CAPShift.ini, Settings, TimeOut
sleep 100
reload
}
return
MNUMBERLOCK:
MsgBox, 4, CAPShift: Numlock, Select Yes if you want sticky NumLock, or No if you want this program to ignore NumLock
IfMsgBox Yes
{
iniWrite, true, CAPShift.ini, Settings, toggleNumLock
}
else IfMsgBox No
{
iniWrite, false, CAPShift.ini, Settings, toggleNumLock
}
sleep 100
reload
return
MINSERT:
MsgBox, 4, CAPShift: Insert, Select Yes if you want sticky Insert, or No if you want this program to ignore Insert
IfMsgBox Yes
{
iniWrite, true, CAPShift.ini, Settings, toggleInsert
}
else IfMsgBox No
{
iniWrite, false, CAPShift.ini, Settings, toggleInsert
}
sleep 100
reload
return
MTOGGLE:
MsgBox, 4, CAPShift:Capslock/Numlock Toogle Menu, Select Yes if you want a combined Capslock Toggle and a combined Numlock Toggle in the menu or No if you want separate On and Off commands for each.
IfMsgBox Yes
{
iniWrite, true, CAPShift.ini, Settings, ToggleCaps
}
else IfMsgBox No
{
iniWrite, false, CAPShift.ini, Settings, ToggleCaps
}
sleep 100
reload
return
MPROGRESS:
MsgBox, 4, CAPShift: Progress Bars, Select Yes if you want a progress bar showing how long left to hold CapsLock or NumLock, or No if you don't want a progress bar
IfMsgBox Yes
{
iniWrite, true, CAPShift.ini, Settings, progressBar
}
else IfMsgBox No
{
iniWrite, false, CAPShift.ini, Settings, progressBar
}
sleep 100
reload
return
MTOOLTIPS:
MsgBox, 4, CAPShift: Tooltips, Select Yes if you want tooltips showing capslock status after activation or No if you don't want them
IfMsgBox Yes
{
iniWrite, true, CAPShift.ini, Settings, enableTooltips
}
else IfMsgBox No
{
iniWrite, false, CAPShift.ini, Settings, enableTooltips
}
sleep 100
reload
return
ABOUT:
MsgBox,0,CAPShift,%About%
Return
QUIT:
ExitApp