단축키를 눌러서 한글을 영어로 번역하는 프로그램
# 콘솔 출력안되게
# https://wikidocs.net/21952#_2
# pyinstaller --onefile --windowed 6_myproject/9_wikipia_flag_imgae_download.py
# pip install pyinstaller
# 참고사이트
# https://coding-kindergarten.tistory.com/98
# 위키독스
# https://wikidocs.net/137922
# https://wikidocs.net/151324
import keyboard
import pyperclip
import pyautogui
from googletrans import Translator
def hello():
pyautogui.sleep(0.2)
pyautogui.keyDown('ctrl')
pyautogui.press('a')
pyautogui.sleep(0.1)
pyautogui.keyUp('ctrl')
pyautogui.sleep(0.1)
pyautogui.hotkey("ctrlleft", "x")
# Get text from clipboard
stringHangel = pyperclip.paste()
# print(stringHangel)
# Translate text to English
translator = Translator()
translated_text = translator.translate(stringHangel, src='ko', dest='en').text
# Put translated text in clipboard
pyperclip.copy(translated_text)
# print(translated_text)
pyautogui.hotkey("ctrlleft", "v")
pyautogui.sleep(0.2)
pyautogui.press('enter')
pyautogui.sleep(0.2)
pyautogui.press('enter')
print('program start')
# Register a hotkey to trigger the function
keyboard.add_hotkey('alt+/', hello)
# Wait for hotkeys to be triggered
keyboard.wait("esc") # 사용자가 esc를 누를때까지 프로그램 수행
print('program end')