⚡ Ultra-fast native clipboard access — stable copy/paste without Java clipboard bugs
// Quick Start — Stable clipboard operations
FastClipboard clipboard = new FastClipboard();
// Copy text to clipboard
clipboard.setClipboardText("Hello, World!");
// Get text from clipboard
String text = clipboard.getClipboardText();
// Copy image to clipboard
int[] pixels = new int[100 * 100];
clipboard.setClipboardImage(100, 100, pixels);
// Copy file list to clipboard
String[] files = {"C:\\file1.txt", "C:\\file2.txt"};
clipboard.setClipboardFiles(files);FastClipboard is a high-performance Java clipboard library that replaces java.awt.Toolkit.getDefaultToolkit().getSystemClipboard() with a native Windows backend using Win32 API calls. Built for stable text operations, image handling, file transfer, and format detection. Supports CF_UNICODETEXT, CF_DIB (images), and CF_HDROP (file lists) formats.
Keywords: java clipboard alternative, native clipboard jni, win32 clipboard api, fast copy paste java, clipboard stability, java clipboard bug fix, windows clipboard automation, jni clipboard, clipboard image support, file list clipboard
If you need reliable clipboard operations, image transfer, or file drag-and-drop without Java's clipboard bugs, FastClipboard delivers native-level performance with Java simplicity.
- Why FastClipboard?
- Key Features
- Performance Benchmarks
- Installation
- Quick Start
- API Reference
- Build from Source
- Platform Support
- Use Cases
- License
java.awt.Toolkit.getDefaultToolkit().getSystemClipboard() is convenient but buggy:
- Clipboard ownership issues
- Intermittent failures
- Thread-safety problems
- Slow performance
FastClipboard solves this with:
- Direct Win32 API calls —
OpenClipboard,GetClipboardData,SetClipboardData - Stable operation — no ownership issues
- UTF-8/Unicode support — proper text encoding
- Minimal footprint — 1 header + 1 JNI file + 1 Java class
- 1-evening implementation — simple and maintainable
- Direct Win32 API access — stable clipboard operations
- Text support — UTF-8/Unicode text with proper encoding
- Image support — DIB format (CF_DIB) for bitmap images
- File list support — CF_HDROP format for file operations
- Format detection — check available clipboard formats
- Minimal footprint — small DLL, simple API
- MIT licensed — free for commercial use
- Windows-only — maximum performance on the most common platform
| Operation | Java AWT Clipboard | FastClipboard | Speedup |
|---|---|---|---|
| Set Text (1000 iterations) | ~5000μs | ~2000μs | 2.5× |
| Get Text (1000 iterations) | ~3000μs | ~1500μs | 2.0× |
| Full Cycle (1000 iterations) | ~8000μs | ~3500μs | 2.3× |
Measured on Windows 11, Intel Core i7, Java 17
Run the benchmark:
# Compile native DLL first
compile.bat
# Run benchmark
mvn compile exec:java -Dexec.mainClass="fastclipboard.Benchmark"<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependency>
<groupId>com.github.andrestubbe</groupId>
<artifactId>fastclipboard</artifactId>
<version>1.0.0</version>
</dependency>repositories {
maven { url 'https://jitpack.io' }
}
dependencies {
implementation 'com.github.andrestubbe:fastclipboard:1.0.0'
}Download the pre-built JAR with embedded native library:
📥 Download fastclipboard-1.0.0.jar (64 KB)
# Run directly
java -cp fastclipboard-1.0.0.jar fastclipboard.Demoimport fastclipboard.FastClipboard;
FastClipboard clipboard = new FastClipboard();
// Copy text to clipboard
boolean success = clipboard.setClipboardText("Hello, World!");
// Get text from clipboard
String text = clipboard.getClipboardText();
System.out.println("Clipboard: " + text);
// Check if clipboard has text
if (clipboard.hasClipboardText()) {
System.out.println("Clipboard contains text");
}
// Clear clipboard
clipboard.clearClipboard();Enable the watcher for 570× faster repeated clipboard reads via automatic caching:
FastClipboard clipboard = new FastClipboard();
// Enable watcher (opt-in, zero overhead when disabled)
clipboard.enableWatcher();
// First read fetches from clipboard (~500μs)
String text = clipboard.getClipboardText();
// Subsequent reads use cache (~1μs) - 570× faster!
for (int i = 0; i < 1000; i++) {
String cached = clipboard.getClipboardText(); // No JNI call!
}
// Cache auto-invalidates when clipboard changes externally
// Disable when done
clipboard.disableWatcher();When to use:
- Bots/Agents with frequent clipboard polling
- Vision pipelines reading clipboard repeatedly
- Any scenario with >100 reads/second
Zero overhead design:
- Disabled by default - no threads, no events
- Opt-in only when needed
- Automatically invalidates cache on clipboard changes
// Check if specific format is available
if (clipboard.isFormatAvailable(FastClipboard.CF_UNICODETEXT)) {
System.out.println("Unicode text available");
}
// Get number of available formats
int formatCount = clipboard.getFormatCount();
System.out.println("Available formats: " + formatCount);// Copy image to clipboard (RGBA pixel data)
int width = 100;
int height = 100;
int[] pixels = new int[width * height];
// Fill with RGBA pixel data (0xAARRGGBB)
for (int i = 0; i < pixels.length; i++) {
pixels[i] = 0xFFFF0000; // Red pixels
}
boolean success = clipboard.setClipboardImage(width, height, pixels);
// Get image from clipboard
int[] imageData = clipboard.getClipboardImage();
if (imageData != null) {
int imgWidth = imageData[0];
int imgHeight = imageData[1];
int[] imgPixels = new int[imageData.length - 2];
System.arraycopy(imageData, 2, imgPixels, 0, imgPixels.length);
}
// Check if clipboard has image
if (clipboard.hasClipboardImage()) {
System.out.println("Clipboard contains image");
}// Copy file list to clipboard
String[] files = {"C:\\path\\to\\file1.txt", "C:\\path\\to\\file2.txt"};
boolean success = clipboard.setClipboardFiles(files);
// Get file list from clipboard
String[] clipboardFiles = clipboard.getClipboardFiles();
if (clipboardFiles != null) {
for (String file : clipboardFiles) {
System.out.println("File: " + file);
}
}
// Check if clipboard has file list
if (clipboard.hasClipboardFiles()) {
System.out.println("Clipboard contains file list");
}setClipboardText(String text)— Copy text to clipboardgetClipboardText()— Get text from clipboardhasClipboardText()— Check if clipboard contains textclearClipboard()— Clear clipboard contents
setClipboardImage(int width, int height, int[] pixels)— Copy RGBA image to clipboard (DIB format)getClipboardImage()— Get image from clipboard (returns [width, height, pixelData...])hasClipboardImage()— Check if clipboard contains image
setClipboardFiles(String[] filePaths)— Copy file list to clipboard (CF_HDROP format)getClipboardFiles()— Get file list from clipboardhasClipboardFiles()— Check if clipboard contains file list
isFormatAvailable(int format)— Check if format is availablegetFormatCount()— Get number of available formats
CF_TEXT = 1— ANSI textCF_UNICODETEXT = 13— Unicode text (UTF-16)CF_BITMAP = 2— Bitmap imageCF_DIB = 8— Device Independent BitmapCF_HDROP = 15— File list
Download: https://www.oracle.com/java/technologies/downloads/ or https://adoptium.net/
Verify installation:
java -version
javac -versionDownload: https://visualstudio.microsoft.com/downloads/
Required components:
- ✅ Desktop development with C++ workload
- ✅ Windows 10/11 SDK
- ✅ MSVC v142/v143 - VS 2019/2022 C++ x64/x86 build tools
Download: https://maven.apache.org/download.cgi
git clone https://github.com/andrestubbe/fastclipboard.git
cd fastclipboard
# Compile native DLL
compile.bat
# Build Java + package
mvn clean package| Platform | Version | Status |
|---|---|---|
| Windows 11 | v1.0 | ✅ Full support (Win32 API) |
| Windows 10 | v1.0 | ✅ Full support (Win32 API) |
| Linux | — | ❌ Not planned |
| macOS | — | ❌ Not planned |
Windows-only by design — we focus on maximum performance on the most common platform.
- Automation scripts — reliable clipboard operations
- Data processing pipelines — fast text transfer
- Bot development — stable clipboard interaction
- Test automation — consistent clipboard behavior
- Desktop applications — bug-free clipboard access
MIT License — free for commercial and private use. See LICENSE for details.
- FastHotkey - Ultra-fast global hotkey library
- FastRobot - High-performance screen capture
- FastGraphics - GPU-accelerated graphics
- FastTheme - OS-aware Display/Theme monitor
If FastClipboard helps you build something awesome:
- Star the repository ⭐
- Share with other developers
- Report issues and suggest features
- Contribute improvements via pull requests
Small package. Maximum speed. Zero bloat. 🚀📋
Replace buggy Java clipboard with stable native performance!