An AutoHotkey v2 library for interacting with the Windows Clipboard History, leveraging the WinRT API for enhanced functionality and performance. This library allows you to retrieve, manipulate, and utilize clipboard history items efficiently.
Retrieve a list of all items stored in the clipboard history and get the text, HTML, and other supported formats of each history item.
Clear the clipboard history or delete individual items.
Replace the current clipboard content with a selected history item.
- AutoHotkey v2+
- Windows 10 or later (with Clipboard History enabled in System Settings)
- Download: Download the library files from the GitHub repository.
- Place Files:
- Place
ClipboardHistory.ahk
in the same directory as your main AutoHotkey script (e.g.,YourMainScript.ahk
). - Place the
winrt.ahk-main
folder in theLib
folder within your script's directory.
- Place
- Include in Script:
-
If
ClipboardHistory.ahk
is in the same directory asYourMainScript.ahk
:#Include ClipboardHistory.ahk
Directory structure should look like this:
...\AutoHotkey\ ├── YourMainScript.ahk ├── ClipboardHistory.ahk └── Lib\ └── winrt.ahk-main\ ├── winrt.ahk ├── windows.ahk └── ...
-
If
ClipboardHistory.ahk
is in aLib
folder:#Include <ClipboardHistory>
Directory structure should look like this:
...\AutoHotkey\ ├── YourMainScript.ahk └── Lib\ ├── ClipboardHistory.ahk └── winrt.ahk-main\ ├── winrt.ahk ├── windows.ahk └── ...
-
The library provides a ClipboardHistory
class with static methods and properties for interacting with the clipboard history.
-
Display all clipboard history items in message boxes:
#Requires AutoHotkey v2 #Include <ClipboardHistory> ; Or #Include ClipboardHistory.ahk if not using the Lib folder if (!A_IsCompiled && A_LineFile = A_ScriptFullPath) Loop count := ClipboardHistory.Count if texts := ClipboardHistory.GetText(A_Index) MsgBox(texts, "Clipboard History Item Index: " A_Index " of " count)
-
Retrieves the third item from your clipboard history and places it into your current clipboard. (This works with any type of content.)
ClipboardHistory.SetItemAsContent(3)
Property | Description |
---|---|
Count |
Returns the number of items in the clipboard history. |
IsEnabled |
Checks if clipboard history is enabled. |
Method | Description |
---|---|
GetText(index) |
Retrieves the text content of the item at the specified index. |
GetHtml(index, convertToText, &source?) |
Retrieves the HTML content of the item at the specified index. Optionally converts HTML to plain text and retrieves the source URL. |
AvailableFormats(indexOrContent) |
Returns a pipe-separated list of available formats for the given index or content. |
Clear() |
Clears the entire clipboard history. |
DeleteItem(indexOrItem) |
Deletes a specific item from the history. |
SetItemAsContent(index) |
Sets a history item as the current clipboard content. |
For detailed information on the API, please refer to the Microsoft Learn documentation.
Contributions are welcome! Please feel free to submit issues or pull requests.
This project is licensed under the MIT License.