import pandas as pd
import time
import sys
import os
import pyperclip
from pynput import keyboard
def get_txt():
return pyperclip.paste()
def on_activate(data_txt):
df = pd.DataFrame(data_txt, columns={'txt'}, dtype='string')
df.to_csv('text.csv', index=False, mode='a', header=False)
print('Global hotkey activated!')
def for_canonical(f):
return lambda k: f(l.canonical(k))
hotkey = keyboard.HotKey(
keyboard.HotKey.parse('<ctrl>+b'),
on_activate)
l = keyboard.Listener(on_press=for_canonical(hotkey.press),on_release=for_canonical(hotkey.release))
def main():
sys.path.append(os.path.abspath("SO_site-packages"))
data_txt = []
recent_value = ""
while True:
tmp_value = pyperclip.paste() # 读取剪切板复制的内容
if tmp_value != recent_value: # 如果检测到剪切板内容有改动,那么就进入文本的修改
recent_value = tmp_value
data_txt.append(recent_value)
print('已复制内容:%s' % str(data_txt))
time.sleep(0.1)
l.start()
l.join()
if __name__ == "__main__":
main()