You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
1.3 KiB

2 years ago
import time
import sys
import os
import re
# pip3 install install pyperclip
sys.path.append(os.path.abspath("SO_site-packages"))
import pyperclip # 引入模块
recent_value = ""
tmp_value = "" # 初始化应该也可以没有这一行感觉意义不大。但是对recent_value的初始化是必须的
while True:
tmp_value = pyperclip.paste() # 读取剪切板复制的内容
if tmp_value != recent_value: # 如果检测到剪切板内容有改动,那么就进入文本的修改
recent_value = tmp_value
lines = recent_value.split('\r\n')
changed = "\"Title\":{\"prefix\":\"ActionName\",\"body\": ["
cnt=0
for line in lines:
line = line.replace('"', '\\"')
line = '"' + line + '"'
cnt=cnt+1
if cnt>1:
changed = changed + ',\r\n' + line # 将文本的换行符去掉,变成一个空格
else:
changed = changed + '\r\n' + line # 将文本的换行符去掉,变成一个空格
changed =changed+"]},"
recent_value = changed
pyperclip.copy(changed) # 将修改后的文本写入系统剪切板中
print("\n Value changed: %s" % str(changed)) # 输出已经去除换行符的文本
time.sleep(0.1)