-
-
Save MaxSteven/f741e92d9b1156596f1efb3adb9ce764 to your computer and use it in GitHub Desktop.
Maya get_clipboard_data
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
| def get_clipboard_data(): | |
| """ | |
| Get data from the clipboard | |
| *Arguments:* | |
| * ``None`` | |
| *Keyword Arguments:* | |
| * ``None`` | |
| *Returns:* | |
| * ``None`` | |
| *Author:* | |
| * randall.hess, 4/24/2017 4:33:06 PM | |
| """ | |
| data = None | |
| kernel32 = ctypes.windll.kernel32 | |
| user32 = ctypes.windll.user32 | |
| user32.OpenClipboard(0) | |
| CF_TEXT = 1 | |
| if user32.IsClipboardFormatAvailable(CF_TEXT): | |
| hClipMem = user32.GetClipboardData(CF_TEXT) | |
| kernel32.GlobalLock.restype = ctypes.c_char_p | |
| data = kernel32.GlobalLock(hClipMem) | |
| kernel32.GlobalUnlock(hClipMem) | |
| user32.CloseClipboard() | |
| if isinstance(data, str): | |
| return data | |
| elif hasattr(data, 'decode'): | |
| data = value.decode(sys.getfilesystemencoding()) | |
| return data | |
| else: | |
| return '' | |
| user32.CloseClipboard() | |
| return data |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment