复制提示 Python脚本

2023-10-23 09:47:15 浏览数 (2)

作为CV工程师,CTRL C键会经常失灵。 所有写了一个python 脚本来监听剪贴板的变化在复制成功发出提示音 pip install pyperclip

代码语言:javascript复制
import pyperclip
import time
def tip():
    """提示"""
    import winsound
    duration = 500  # millisecond
    freq = 440  # Hz
    winsound.Beep(freq, duration)
def check_clipboard():
    """监听剪贴板"""
    previous_text = pyperclip.paste()
    while True:
        time.sleep(0.2)
        current_text = pyperclip.paste()
        if current_text != previous_text:
            print(previous_text,current_text)
            tip()
            previous_text = current_text
if __name__ == "__main__":
    check_clipboard()

0 人点赞