Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement