python3 操作windows的粘贴板(读取和传值)

时间:2023-12-17 17:04:32
#!/usr/bin/env python
# -*- coding:utf-8 -*-
__author__ = "loki" import win32con
import win32clipboard as wincld def get_text():
wincld.OpenClipboard()
text_result = wincld.GetClipboardData(win32con.CF_UNICODETEXT)
wincld.CloseClipboard()
return text_result def set_text(info):
wincld.OpenClipboard()
wincld.EmptyClipboard()
wincld.SetClipboardData(win32con.CF_UNICODETEXT, info)
wincld.CloseClipboard() # set clipboard
set_text('loki_demo') # read clipboard
print(get_text())