Advertisement
Python253

clear_clipboard_history

May 31st, 2024 (edited)
657
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.62 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # Filename: clear_clipboard_history.py
  4. # Version: 1.0.0
  5. # Author: Jeoi Reqi
  6.  
  7. """
  8. Description:
  9.    - This script clears the current content of the clipboard and clipboard history on Windows OS.
  10.    
  11. Requirements:
  12.    - Python 3.x
  13.    - Windows OS
  14.    
  15. Functions:
  16.    - disable_clipboard:
  17.        Clears the current content of the clipboard.
  18.    - clear_clipboard_history_cmd:
  19.        Clears the clipboard history on Windows using Command Prompt.
  20.    
  21. Usage:
  22.    - Run this script in a Python environment.
  23.  
  24. Additional Notes:
  25.    - This script utilizes ctypes and subprocess modules for interacting with the Windows clipboard and executing commands.
  26.    - ctypes is used to interact with the Windows API functions for clipboard manipulation.
  27.    - subprocess is used to run a command in Command Prompt to clear the clipboard history.
  28. """
  29.  
  30. import ctypes
  31. import subprocess
  32.  
  33. def disable_clipboard():
  34.     """
  35.    Clears the current content of the clipboard.
  36.    """
  37.     # Open the clipboard
  38.     ctypes.windll.user32.OpenClipboard(0)
  39.  
  40.     # Empty the clipboard by setting its data to None
  41.     ctypes.windll.user32.EmptyClipboard()
  42.  
  43.     # Close the clipboard
  44.     ctypes.windll.user32.CloseClipboard()
  45.  
  46. def clear_clipboard_history_cmd():
  47.     """
  48.    Clears the clipboard history on Windows using Command Prompt.
  49.    """
  50.     # Clear clipboard history using Command Prompt
  51.     subprocess.run('cmd /c echo.|clip', shell=True)
  52.  
  53. if __name__ == "__main__":
  54.     # Call functions to clear clipboard and clipboard history
  55.     disable_clipboard()
  56.     clear_clipboard_history_cmd()
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement