Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将结果导入ctrl-c内存的Python脚本_Python_Windows_Memory_Copy Paste_Ctrl - Fatal编程技术网

将结果导入ctrl-c内存的Python脚本

将结果导入ctrl-c内存的Python脚本,python,windows,memory,copy-paste,ctrl,Python,Windows,Memory,Copy Paste,Ctrl,我想知道python脚本是否可能将结果导入windows上的剪贴板(ctrl-C内存)。这将使我能够更轻松地操纵传输结果 有可能吗?怎么做?它被称为“剪贴板” 抄袭自: 你说的“ctrl-c内存”是什么意思?你是说剪贴板吗?可能是复制的 import ctypes def winSetClipboard(text): GMEM_DDESHARE = 0x2000 ctypes.windll.user32.OpenClipboard(0) ctypes.windll.use

我想知道python脚本是否可能将结果导入windows上的剪贴板(ctrl-C内存)。这将使我能够更轻松地操纵传输结果

有可能吗?怎么做?

它被称为“剪贴板”

抄袭自:

你说的“ctrl-c内存”是什么意思?你是说剪贴板吗?可能是复制的
import ctypes
def winSetClipboard(text):
    GMEM_DDESHARE = 0x2000
    ctypes.windll.user32.OpenClipboard(0)
    ctypes.windll.user32.EmptyClipboard()
    try:
        # works on Python 2 (bytes() only takes one argument)
        hCd = ctypes.windll.kernel32.GlobalAlloc(GMEM_DDESHARE, len(bytes(text))+1)
    except TypeError:
        # works on Python 3 (bytes() requires an encoding)
        hCd = ctypes.windll.kernel32.GlobalAlloc(GMEM_DDESHARE, len(bytes(text, 'ascii'))+1)
    pchData = ctypes.windll.kernel32.GlobalLock(hCd)
    try:
        # works on Python 2 (bytes() only takes one argument)
        ctypes.cdll.msvcrt.strcpy(ctypes.c_char_p(pchData), bytes(text))
    except TypeError:
        # works on Python 3 (bytes() requires an encoding)
        ctypes.cdll.msvcrt.strcpy(ctypes.c_char_p(pchData), bytes(text, 'ascii'))
    ctypes.windll.kernel32.GlobalUnlock(hCd)
    ctypes.windll.user32.SetClipboardData(1,hCd)
    ctypes.windll.user32.CloseClipboard()