1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# -*- coding: utf-8 -*-

import win32clipboard as wc
import win32con
import sys



def getCopyText():
wc.OpenClipboard()
try:
copy_text = wc.GetClipboardData(win32con.CF_TEXT)
wc.CloseClipboard()
return copy_text
except TypeError:
return "Target Copied Binary."

result = getCopyText()
if len(sys.argv) == 2 and sys.argv[1] == "-f":
with open("CopyText.txt",'a') as copy:
copy.write(result)
else:
#import chardet
#print chardet.detect(getCopyText()) # 找到包含中文内容的字符串编码
print result#.decode('GB2312') # 转码