clipboard.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:jaraco.windows 作者: jaraco 项目源码 文件源码
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()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号