小编chr*_*tor的帖子

使用ctypes在Windows中从剪贴板读取文本

我正在尝试仅使用ctypesin 来获取存储在剪贴板中的文本Python 3.6。我测试了在Stack和GitHub上找到的许多解决方案,但它们仅适用Python 2Python 3.4

这是几乎到处都可以找到的代码:

from ctypes import *

def get_clipboard_text():
    text = ""
    if windll.user32.OpenClipboard(c_int(0)):
        h_clip_mem = windll.user32.GetClipboardData(1)
        windll.kernel32.GlobalLock.restype = c_char_p
        text = windll.kernel32.GlobalLock(c_int(h_clip_mem))
        windll.kernel32.GlobalUnlock(c_int(h_clip_mem))
        windll.user32.CloseClipboard()
    return text
Run Code Online (Sandbox Code Playgroud)

我在中进行了测试Python 3.4。它工作正常,并返回剪贴板中的文本。但是对Python 3.6始终运行相同的脚本总是会返回NonePython 3.6到目前为止,我找不到解决方案。

我想知道是否有人可以帮助我,因为我对编程ctypesC编程一无所知。

python clipboard ctypes python-3.6

3
推荐指数
1
解决办法
784
查看次数

标签 统计

clipboard ×1

ctypes ×1

python ×1

python-3.6 ×1