-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathar-en-replace.ahk
281 lines (195 loc) · 6.48 KB
/
ar-en-replace.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
;A script that changes arabic text to english text and vice-versa then switches to the language you meant to write in
;
;Instructions: - Highlight the text you want to replace and press alt+q (this hotkey can be changed at line 10)
;
;Notes:
; - The script only works if you have exactly two keyboard languages
FileEncoding, UTF-8
LAlt & q:: ;you can change this to whatever you like
;store contents of current windows clipboard so it can later be restored
oldclip := ClipboardAll
;clear clipboard
clipboard =
previousletter =
currentKeyboardLang := Format("{1:#x}",DllCall("GetKeyboardLayout", Int,DllCall("GetWindowThreadProcessId", int,WinActive("A"), Int,0)))
;send cut command with hamza instead of x if the current keyboard language is one of these Arabic keyboard variants:
; SA, Algeria, Bahrain, Egypt, Iraq, Jordan, Kuwait, Lebanon, Libya, Morocco, Oman, Qatar, Syria, Tunisia, UAE, Yemen
if currentKeyboardLang in 0x4010401,0xfffffffff0291401,0x4013c01,0x4010801,0x4010801,0x4012c01,0x4013401,0x4013001,0x4011001,0xfffffffff0291801,0x4012001,0x4014001,0x4012801,0xfffffffff0291c01,0x4013801,0x4012401
Send, {Control Down}ء{Control Up}
else
Send, {Control Down}x{Control Up}
;I forgot why this is important, but it's probably still needed
ClipWait, 1
;this usually happens when you're trying to convert an empty string
if ErrorLevel
MsgBox, something went wrong`, did you highlight a string before trying to convert the text?
;store the string we got from cutting in a seperate variable
clip := clipboard
;go through an incredibly long list of ifs because ahk doesn't have a switch statement ¯\_(ツ)_/¯
Loop, parse, clip
{
if(A_LoopField = "``")
SendRaw, ذ
else if(A_LoopField = "q" or A_LoopField = "Q")
SendRaw, ض
else if(A_LoopField = "w" or A_LoopField = "W")
SendRaw, ص
else if(A_LoopField = "e" or A_LoopField = "E")
SendRaw, ث
else if(A_LoopField = "r" or A_LoopField = "R")
SendRaw, ق
else if(A_LoopField = "t" or A_LoopField = "T")
SendRaw, ف
else if(A_LoopField = "y" or A_LoopField = "Y")
SendRaw, غ
else if(A_LoopField = "u" or A_LoopField = "U")
SendRaw, ع
else if(A_LoopField = "i" or A_LoopField = ""I)
SendRaw, ه
else if(A_LoopField = "o" or A_LoopField = "O")
SendRaw, خ
else if(A_LoopField = "p" or A_LoopField = "P")
SendRaw, ح
else if(A_LoopField = "[")
SendRaw, ج
else if(A_LoopField = "]")
SendRaw, د
else if(A_LoopField = "a" or A_LoopField = "A")
SendRaw, ش
else if(A_LoopField = "s" or A_LoopField = "S")
SendRaw, س
else if(A_LoopField = "d" or A_LoopField = "D")
SendRaw, ي
else if(A_LoopField = "f" or A_LoopField = "F")
SendRaw, ب
else if(A_LoopField = "g" or A_LoopField = "G")
SendRaw, ل
else if(A_LoopField = "h" or A_LoopField = "H")
SendRaw, ا
else if(A_LoopField = "j" or A_LoopField = "J")
SendRaw, ت
else if(A_LoopField = "k" or A_LoopField = "K")
SendRaw, ن
else if(A_LoopField = "l" or A_LoopField = "L")
SendRaw, م
else if(A_LoopField = ";")
SendRaw, ك
else if(A_LoopField = "'")
SendRaw, ط
else if(A_LoopField = "z" or A_LoopField = "Z")
SendRaw, ئ
else if(A_LoopField = "x" or A_LoopField = "X")
SendRaw, ء
else if(A_LoopField = "c" or A_LoopField = "C")
SendRaw, ؤ
else if(A_LoopField = "v" or A_LoopField = "V")
SendRaw, ر
else if(A_LoopField = "b" or A_LoopField = "B")
SendRaw, لا
else if(A_LoopField = "n" or A_LoopField = "N")
SendRaw, ى
else if(A_LoopField = "m" or A_LoopField = "M")
SendRaw, ة
else if(A_LoopField = "?")
SendRaw, ؟
else if(A_LoopField = ",")
SendRaw, و
else if(A_LoopField = ".")
SendRaw, ز
else if(A_LoopField = "/")
SendRaw, ظ
else if(A_LoopField = "ذ")
SendRaw, ``
else if(A_LoopField = "ض")
SendRaw, q
else if(A_LoopField = "ص")
SendRaw, w
else if(A_LoopField = "ث")
SendRaw, e
else if(A_LoopField = "ق")
SendRaw, r
else if(A_LoopField = "ف")
SendRaw, t
else if(A_LoopField = "غ")
SendRaw, y
else if(A_LoopField = "ع")
SendRaw, u
else if(A_LoopField = "ه")
SendRaw, i
else if(A_LoopField = "خ")
SendRaw, o
else if(A_LoopField = "ح")
SendRaw, p
else if(A_LoopField = "ج")
SendRaw, [
else if(A_LoopField = "د")
SendRaw, ]
else if(A_LoopField = "ش")
SendRaw, a
else if(A_LoopField = "س")
SendRaw, s
else if(A_LoopField = "ي")
SendRaw, d
else if(A_LoopField = "ب")
SendRaw, f
else if(A_LoopField = "ل")
SendRaw, g
else if(A_LoopField = "ا")
;if you meant to type in english, pressing "b" results in "لا", so any instance of "لا" will be changed to "b" by the script instead of "gh", this has the disadvantage of having words like "ghost" changed to "bost"
if(previousletter = "ل")
Send, {Backspace}b
else
SendRaw, h
else if(A_LoopField = "ت")
SendRaw, j
else if(A_LoopField = "ن")
SendRaw, k
else if(A_LoopField = "م")
SendRaw, l
else if(A_LoopField = "ك")
SendRaw, `;
else if(A_LoopField = "ط")
SendRaw, '
else if(A_LoopField = "ئ")
SendRaw, z
else if(A_LoopField = "ء")
SendRaw, x
else if(A_LoopField = "ؤ")
SendRaw, c
else if(A_LoopField = "ر")
SendRaw, v
else if(A_LoopField = "لا")
SendRaw, b
else if(A_LoopField = "ى")
SendRaw, n
else if(A_LoopField = "ة")
SendRaw, m
else if(A_LoopField = "و")
SendRaw, `,
else if(A_LoopField = "ز")
SendRaw, .
else if(A_LoopField = "ظ")
SendRaw, /
else if(A_LoopField = "؟")
SendRaw, ?
;if they're not letters just paste whatever was in the clipboard
else
Send, %A_LoopField%
previousletter = %A_LoopField%
}
;switch to the language you meant to write in
Send, {LWin down}{Space}{LWin up}
;I have no idea why past me decided this variable should be emptied but i'm not going to argue with him
clip =
;restore the windows clipboard
clipboard := oldclip
;I have no idea why past me decided this variable should also be emptied but i'm still not going to argue with him
oldclip =
Return
;a few replacements that help when trying to switch languages in MS office and other applications
Shift & Alt::
Send, {LWin down}{Space}{LWin up}
Return
Alt & Shift::
Send, {LWin down}{Space}{LWin up}
Return