1. 簡介
純屬原創,歡迎轉載,但請申明轉載地址:https://blog.csdn.net/qq_33766091/article/details/102379374
由於英文 pdf 剪貼到有道詞典翻譯的時候,每個換行都需要手動去掉,這垃圾設定煩了我很久。故在積累足夠“怒氣”後,下定決心解決下。
解決完後感覺,人生苦短,python真好。簡單功能沒必要苛求性能,有脾氣把我3700X也給撐爆呀,哈哈(當然,這簡單功能基本CPU都喂不飽,這裏只是裝機後貧窮滴得瑟)。
2. 效果
3. 代碼
#!/usr/bin/env python
# coding: utf-8
from system_hotkey import SystemHotkey
import pyperclip as pyclip
import time
# 剪貼板字符串處理
def StringProcess(self):
# 讀取字符串(剪貼板)
read_text = pyclip.paste()
# 字符串處理
output_text = read_text.replace("\r\n", " ")
output_text = output_text.replace("\n", " ")
output_text = output_text.replace("\r", " ")
# 輸出字符串(剪貼板)
pyclip.copy(output_text)
# 綁定熱鍵 ctrl+shift+m ,回調執行 StringProcess()
hk = SystemHotkey()
hk.register(('control', 'shift', 'm'), callback=StringProcess)
# 等待,可能不需要
while (1):
time.sleep(1000)
備註:
- 可以用pyinstaller 對python程序打包,方便使用;
- 熱鍵功能官方庫不支持mac/python2。
4. 參考鏈接:
https://pypi.org/project/system_hotkey/1.0.3/(這裏用到 pypi 的system_hotkey 庫)
https://www.runoob.com/python/att-string-replace.html