python 实时监控剪切板,并替换其中的部分内容,重新写入剪切板

#实时监控剪贴板内容的变化,并替换其中的回车,换行,逗号,再写入剪切板,以供使用。
import pyperclip
import time


last_string = pyperclip.paste()
while True:
    # 检测频率
    time.sleep(0.2)
    string = pyperclip.paste()#读取剪切板内容
    if string != last_string and string != '':
        #print([string])
        print(string)
        output_text = string.replace("\r\n", "")
        output_text = output_text.replace("\n", "")
        output_text = output_text.replace("\r", "")
        output_text = output_text.replace(",", "")
        # 输出字符串(剪贴板)
        pyperclip.copy(output_text)#重新写入剪切板
        last_string = string

 

posted @ 2021-01-30 21:42  myrj  阅读(676)  评论(0编辑  收藏  举报