Skip to content

Instantly share code, notes, and snippets.

@udf
Created July 6, 2020 16:28
Show Gist options
  • Save udf/23a992d006b4c8f2984a769f1338804c to your computer and use it in GitHub Desktop.
Save udf/23a992d006b4c8f2984a769f1338804c to your computer and use it in GitHub Desktop.
Prints available clipboard formats on windows
import win32clipboard as clipboard
class ClipboardWrapper:
def __init__(self):
pass
def __enter__(self):
clipboard.OpenClipboard()
def __exit__(self, type, value, traceback):
clipboard.CloseClipboard()
formats = []
with ClipboardWrapper():
format = clipboard.EnumClipboardFormats(0)
formats.append(format)
while 1:
format = clipboard.EnumClipboardFormats(formats[-1])
if format == 0:
break
formats.append(format)
format_names = {}
for format in formats:
name = ''
try:
name = clipboard.GetClipboardFormatName(format)
except:
pass
try:
data = clipboard.GetClipboardData(format)
except:
pass
format_names[format] = name
print(format_names)
breakpoint()
print()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment