Skip to content

Instantly share code, notes, and snippets.

@Rhomboid
Last active November 28, 2019 11:52
Show Gist options
  • Save Rhomboid/5155189 to your computer and use it in GitHub Desktop.
Save Rhomboid/5155189 to your computer and use it in GitHub Desktop.
Enumerate clipboard formats with Python and Pywin32
import win32clipboard
formats = {val: name for name, val in vars(win32clipboard).items() if name.startswith('CF_')}
def format_name(fmt):
if fmt in formats:
return formats[fmt]
try:
return win32clipboard.GetClipboardFormatName(fmt)
except:
return "unknown"
win32clipboard.OpenClipboard(None)
fmt = 0
while True:
fmt = win32clipboard.EnumClipboardFormats(fmt)
if fmt == 0: break
print('{:5} ({})'.format(fmt, format_name(fmt)))
win32clipboard.CloseClipboard()
49161 (DataObject)
49798 (text/html)
49358 (HTML Format)
49871 (text/_moz_htmlcontext)
49872 (text/_moz_htmlinfo)
13 (CF_UNICODETEXT)
1 (CF_TEXT)
49873 (text/x-moz-url-priv)
49171 (Ole Private Data)
16 (CF_LOCALE)
7 (CF_OEMTEXT)
@smunkel
Copy link

smunkel commented Mar 13, 2013

Wouldn't it make more sense to use vars rather than dir here?

@Rhomboid
Copy link
Author

Rhomboid commented Jun 5, 2013

You're right. I edited the gist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment