Exemple #1
0
def SetClipboardData(type, content):
    """
	Modeled after http://msdn.microsoft.com/en-us/library/ms649016%28VS.85%29.aspx#_win32_Copying_Information_to_the_Clipboard
	"""
    allocators = {
        clipboard.CF_TEXT: ctypes.create_string_buffer,
        clipboard.CF_UNICODETEXT: ctypes.create_unicode_buffer,
    }
    if not type in allocators:
        raise NotImplementedError("Only text types are supported at this time")
    # allocate the memory for the data
    content = allocators[type](content)
    flags = memory.GMEM_MOVEABLE
    size = ctypes.sizeof(content)
    handle_to_copy = windll.kernel32.GlobalAlloc(flags, size)
    with LockedMemory(handle_to_copy) as lm:
        ctypes.memmove(lm.data_ptr, content, size)
    result = clipboard.SetClipboardData(type, handle_to_copy)
    if result is None:
        raise WindowsError()
Exemple #2
0
def raw_data(handle):
    return LockedMemory(handle).data