Created
April 27, 2012 23:10
-
-
Save adam-p/2514182 to your computer and use it in GitHub Desktop.
Displays the contents of the Windows clipboard, including all available formats. Created to answer a friend's question about how he could paste both rich and plain text, depending on the target application.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import win32clipboard as cb | |
builtin_type = { | |
2: "CF_BITMAP", | |
8: "CF_DIB", | |
17: "CF_DIBV5", | |
5: "CF_DIF", | |
130: "CF_DSPBITMAP", | |
142: "CF_DSPENHMETAFILE", | |
131: "CF_DSPMETAFILEPICT", | |
129: "CF_DSPTEXT", | |
14: "CF_ENHMETAFILE", | |
15: "CF_HDROP", | |
16: "CF_LOCALE", | |
18: "CF_MAX", | |
3: "CF_METAFILEPICT", | |
7: "CF_OEMTEXT", | |
128: "CF_OWNERDISPLAY", | |
9: "CF_PALETTE", | |
10: "CF_PENDATA", | |
11: "CF_RIFF", | |
4: "CF_SYLK", | |
1: "CF_TEXT", | |
6: "CF_TIFF", | |
13: "CF_UNICODETEXT", | |
12: "CF_WAVE", | |
} | |
cb.OpenClipboard() | |
print 'Number of formats: %d' % cb.CountClipboardFormats() | |
format_id = 0 | |
for i in xrange(cb.CountClipboardFormats()): | |
format_id = cb.EnumClipboardFormats(format_id) | |
print '\n---- ENTRY -----' | |
print format_id | |
format_name = 'FAILED' | |
try: | |
format_name = cb.GetClipboardFormatName(format_id) | |
except: | |
if builtin_type.has_key(format_id): | |
format_name = builtin_type[format_id] | |
print 'Format name: %s' % format_name | |
data = cb.GetClipboardData(format_id) | |
try: | |
data = data.decode() | |
except: | |
pass | |
print data | |
cb.CloseClipboard() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment