I'm trying to get the text stored in the clipboard by just using ctypes
in Python 3.6
. I tested a lot of solutions I found on Stack and GitHub, but they only work for Python 2
to Python 3.4
.
This is the code you'll find almost everywhere:
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
I tested it in Python 3.4
. It worked fine and returned the text in the clipboard. But running the same script on Python 3.6
always returns None
. I could not find a solution for Python 3.6
so far.
I'm wondering if anybody could help me out since I don't know much about ctypes
and C
programming at all.