-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenfaConvertor.py
46 lines (41 loc) · 1.08 KB
/
enfaConvertor.py
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
import keyboard
import pyperclip
en = "qwertyuiop[]\\asdfghjkl;'zxcvbnm,.?"
fa = "ضصثقفغعهخحجچپشسیبلاتنمکگظطزرذدئو.؟"
def Handle():
print('key pressed')
keyboard.send('ctrl+c')
text = pyperclip.paste()
pyperclip.copy(Conver(text))
keyboard.send('ctrl+v')
def GetLang(text):
if text[0] in en or text[-1] in en:
return "en"
elif text[0].lower() in en or text[-1].lower() in en:
return "en"
elif text[0] in fa or text[-1] in fa:
return "fa"
else:
return None
def Conver(text):
lang=GetLang(text)
res=""
if(lang=="en"):
text=text.lower()
for c in text:
if(c in en):
res+=fa[en.index(c)]
else:
res+=c
return res
elif(lang=="fa"):
for c in text:
if(c in fa):
res+=en[fa.index(c)]
else:
res+=c
return res
else:
return text
keyboard.add_hotkey('ctrl+.', Handle)
keyboard.wait()