Created
January 12, 2023 17:39
-
-
Save JanChec/47d15b720ad967ff77a8cb9ebc42d9e6 to your computer and use it in GitHub Desktop.
Windows 11 pasting from clipboard in Python - unicode text and files
This file contains 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 pathlib | |
from typing import List | |
import win32clipboard | |
def paste() -> str | List[pathlib.Path]: | |
try: | |
win32clipboard.OpenClipboard() | |
try: | |
return win32clipboard.GetClipboardData(win32clipboard.CF_UNICODETEXT) | |
except TypeError: | |
raw_paths = win32clipboard.GetClipboardData(win32clipboard.CF_HDROP) | |
return [pathlib.Path(raw) for raw in raw_paths] | |
finally: | |
win32clipboard.CloseClipboard() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment