-
Notifications
You must be signed in to change notification settings - Fork 174
/
Copy pathTransliterateText.ahk
124 lines (118 loc) · 2.7 KB
/
TransliterateText.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
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
StringCaseSense, On
#SingleInstance, Force
SetBatchLines, -1
SetKeyDelay, 10
; Transform all text
$>^>+Space::
; Msgbox Transform all text (RCtrl+RShift+Space)
KeyWait RCtrl
KeyWait RShift
KeyWait Space
savedClip := Clipboard
Sleep 1
Send ^{vk41}^{vk43}
Sleep 1
Clipboard := transformTextLayout(Clipboard)
Sleep 1
Send ^{vk56}
Sleep 1
Clipboard := savedClip
savedClip := ""
Return
; Transform only one (full) line
$>+>!Space::
; Msgbox Transform only one (full) line (RShift+RAlt+Space)
KeyWait RShift
KeyWait RAlt
KeyWait Space
savedClip := Clipboard
Sleep 1
Send {End}+{Home}^{vk43}
Sleep 1
Clipboard := transformTextLayout(Clipboard)
Sleep 1
Send ^{vk56}
Sleep 1
Clipboard := savedClip
savedClip := ""
Return
; Transform only (left) part of a line (from the beginning of the line to the caret)
$>^Space::
; Msgbox Transform only (left) part of a line (from the beginning of the line to the caret) (RCtrl+Space)
KeyWait RCtrl
KeyWait Space
savedClip := Clipboard
Sleep 1
Send +{Home}^{vk43}
Sleep 1
Clipboard := transformTextLayout(Clipboard)
Sleep 1
Send ^{vk56}
Sleep 1
Clipboard := savedClip
savedClip := ""
Return
; Transform only (right) part of a line (from the beginning of the line to the caret)
$>^>!Space::
; Msgbox Transform only (right) part of a line (from the beginning of the line to the caret) (RCtrl+RAlt+Space)
KeyWait RCtrl
KeyWait RAlt
KeyWait Space
savedClip := Clipboard
Sleep 1
Send +{End}^{vk43}
Sleep 1
Clipboard := transformTextLayout(Clipboard)
Sleep 1
Send ^{vk56}
Sleep 1
Clipboard := savedClip
savedClip := ""
Return
; Transform only last word
$>!Space::
; Msgbox Transform only last word (RAlt+Space)
KeyWait RAlt
KeyWait Space
savedClip := Clipboard
Sleep 1
Loop
{
If GetKeyState("Esc", "P")
Exit
Send ^+{Left}
If A_LoopField = 1
Continue
Else
Send ^{vk43}
Sleep 1
IfInString, Clipboard, %A_Space%
{
Send ^+{Right}^{vk43}
Sleep 1
Break
}
}
Clipboard := transformTextLayout(Clipboard)
Sleep 1
Send ^{vk56}
Clipboard := savedClip
savedClip := ""
Return
transformTextLayout(textContainer)
{
en := "``qwertyuiop[]asdfghjkl;'zxcvbnm,./~@#$^&QWERTYUIOP{}|ASDFGHJKL:""ZXCVBNM<>?"
ru := "¸éöóêåíãøùçõúôûâàïðîëäæýÿ÷ñìèòüáþ.¨""¹;:?ÉÖÓÊÅÍÃØÙÇÕÚ/ÔÛÂÀÏÐÎËÄÆÝß×ÑÌÈÒÜÁÞ,"
textContainer ~= "i)[a-z]" ? (layoutIn := en, layoutOut := ru) : (layoutIn := ru, layoutOut := en)
Loop, Parse, textContainer
{
IfNotInString, layoutIn, %A_LoopField%
newChar := A_LoopField
Else
StringReplace, newChar, A_LoopField, %A_LoopField%, % SubStr(layoutOut, InStr(layoutIn, A_LoopField, True), 1)
outputStr .= newChar
}
Return outputStr
}