Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
devwiki:python [2019/12/05 02:23]
ying [OS system operation]
devwiki:python [2020/06/15 03:32] (current)
ying [ctypes]
Line 1586: Line 1586:
 ShellExecuteEx(ctypes.byref(sei)) ShellExecuteEx(ctypes.byref(sei))
 time.sleep(5) time.sleep(5)
 +</​code>​
 +
 +  * get clipboard data (ref: https://​stackoverflow.com/​questions/​101128/​how-do-i-read-text-from-the-windows-clipboard-from-python) <code python>
 +import ctypes
 +def get_clipboard_text():​
 +    ctypes.windll.kernel32.GlobalLock.argtypes = [ctypes.c_void_p]
 +    ctypes.windll.kernel32.GlobalLock.restype = ctypes.c_void_p
 +    ctypes.windll.kernel32.GlobalUnlock.argtypes = [ctypes.c_void_p]
 +    ctypes.windll.user32.GetClipboardData.restype = ctypes.c_void_p
 +
 +    ctypes.windll.user32.OpenClipboard(0)
 +    try:
 +        if ctypes.windll.user32.IsClipboardFormatAvailable(1):​
 +            data = ctypes.windll.user32.GetClipboardData(1)
 +            data_locked = ctypes.windll.kernel32.GlobalLock(data)
 +            text = ctypes.c_char_p(data_locked)
 +            value = text.value
 +            ctypes.windll.kernel32.GlobalUnlock(data_locked)
 +            return value
 +    finally:
 +        ctypes.windll.user32.CloseClipboard()
 +# test
 +print(get_clipboard_text())
 </​code>​ </​code>​
 ===== twisted ===== ===== twisted =====