Get the current clipboard's text on Windows. Requires Mark Hammond's pywin32 extensions.
()
| 10 | pass |
| 11 | |
| 12 | def win32_clipboard_get(): |
| 13 | """ Get the current clipboard's text on Windows. |
| 14 | |
| 15 | Requires Mark Hammond's pywin32 extensions. |
| 16 | """ |
| 17 | try: |
| 18 | import win32clipboard |
| 19 | except ImportError: |
| 20 | raise TryNext("Getting text from the clipboard requires the pywin32 " |
| 21 | "extensions: http://sourceforge.net/projects/pywin32/") |
| 22 | win32clipboard.OpenClipboard() |
| 23 | try: |
| 24 | text = win32clipboard.GetClipboardData(win32clipboard.CF_UNICODETEXT) |
| 25 | except (TypeError, win32clipboard.error): |
| 26 | try: |
| 27 | text = win32clipboard.GetClipboardData(win32clipboard.CF_TEXT) |
| 28 | text = py3compat.cast_unicode(text, py3compat.DEFAULT_ENCODING) |
| 29 | except (TypeError, win32clipboard.error): |
| 30 | raise ClipboardEmpty |
| 31 | finally: |
| 32 | win32clipboard.CloseClipboard() |
| 33 | return text |
| 34 | |
| 35 | def osx_clipboard_get() -> str: |
| 36 | """ Get the clipboard's text on OS X. |