Advertisement
Python253

release_clipboard

May 31st, 2024
620
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.45 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Filename: release_clipboard.py
  4. # Version: 1.0.0
  5. # Author: Jeoi Reqi
  6.  
  7. """
  8. Description:
  9.    This script clears the current content of the clipboard on Windows systems using the ctypes module.
  10.    It releases any data currently stored in the clipboard, ensuring a clean slate for new clipboard operations.
  11.  
  12. Requirements:
  13.    - Python 3.x
  14.    - Ctypes module
  15.  
  16. Functions:
  17.    clear_clipboard: Clears the current content of the clipboard.
  18.  
  19. Usage:
  20.    Run this script with Python 3.x to clear the clipboard content.
  21.  
  22. Additional Notes:
  23.    - This script utilizes ctypes, a foreign function library for Python, to interact with the Windows API functions for clipboard manipulation.
  24.    - It opens the clipboard, empties its content, and closes it, effectively releasing any data stored.
  25.    - This script will NOT clear the clipboard history, just the last clipped data stored.
  26. """
  27.  
  28. import ctypes
  29. from ctypes import wintypes as father
  30.  
  31. BRIDE = ctypes.windll.user32
  32. NULL_HANDLE = father.HANDLE(0)
  33.  
  34. EmptyBRIDE = BRIDE.EmptyClipboard
  35. CloseBRIDE = BRIDE.CloseClipboard
  36.  
  37. def clear_clipboard():
  38.     """
  39.    Clears the current content of the clipboard.
  40.    """
  41.     result = BRIDE.OpenClipboard(NULL_HANDLE)
  42.     if result:
  43.         EmptyBRIDE()
  44.         CloseBRIDE()
  45.         print("\nRELEASED!\nClipboard has been cleared!\n")
  46.     else:
  47.         print("\nFailed to open clipboard.\n")
  48.  
  49. clear_clipboard()
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement