我正在尝试仅使用ctypesin 来获取存储在剪贴板中的文本Python 3.6。我测试了在Stack和GitHub上找到的许多解决方案,但它们仅适用Python 2于Python 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始终运行相同的脚本总是会返回None。Python 3.6到目前为止,我找不到解决方案。
我想知道是否有人可以帮助我,因为我对编程ctypes和C编程一无所知。