๐ฏ Ultra-fast native Win32 cursor pointer shape management, capture, and alpha blending for Java.
FastCursor delivers dual capabilities for high-performance Java applications:
- Pointer Mutation: Sub-microsecond Win32
user32.dllcursor changes (set,setForWindow,get,show,hide) with zero preview flags. - Cursor Capture & Blending: Real-time extraction of the active OS mouse cursor (
captureCursor) and hardware-accelerated alpha blending (blendCursor) directly into screen-recording and streaming frame buffers.
import fastcursor.FastCursor;
import fastcursor.CursorType;
public class QuickStart {
public static void main(String[] args) {
// 1. Immediately change active thread cursor to WAIT spinner
FastCursor.set(CursorType.WAIT);
// 2. Query native Win32 HCURSOR address
long hCursor = FastCursor.get();
System.out.println("Active HCURSOR: 0x" + Long.toHexString(hCursor));
// 3. Restore default arrow
FastCursor.set(CursorType.ARROW);
// 4. Alpha-blend cursor into a frame buffer (for streaming/capture)
int[] framePixels = new int[1920 * 1080];
FastCursor.blendCursor(framePixels, 1920, 1080, 0, 0, false);
}
}- Quick Start
- Why FastCursor?
- Key Features
- Real-World Use Cases
- Architecture & Design
- Supported Cursor Types
- Code Examples
- Performance Benchmarks
- Technical Demos & Benchmarks
- Installation
- Documentation
- Platform Support
- Related Projects
- License
Standard Java cursor handling via java.awt.Cursor or JavaFX is plagued by severe architectural limitations for high-performance apps, games, and system tools:
- Missing System Cursor Shapes: Standard Java only maps a tiny subset of legacy cursors. Essential Windows cursors like
IDC_APPSTARTING,IDC_HELP, orIDC_SIZEALLare either inconsistent or completely missing. - No Window-Level Class Binding: AWT requires continuous hover listening. If the JVM Event Dispatch Thread (EDT) suffers a latency spike, the cursor freezes or exhibits jitter.
- Missing Direct Handle Access: Standard APIs do not expose the underlying Win32
HCURSORhandle needed for integration with low-level graphic APIs or native window frames. - The DLL / JNI Overhead Dilemma: Traditional native workarounds rely on heavyweight JNA wrappers or custom C++ DLLs that require cumbersome compilation, extraction, and platform-specific deployments.
FastCursor circumvents all these limitations through an ultra-fast native Win32 C++ & JNI engine backed by FastCore:
| Feature | Standard Java (java.awt.Cursor) |
Legacy JNA Wrappers | FastCursor (Native JNI) |
|---|---|---|---|
| Underlying Mechanism | AWT Peer abstraction | Dynamic libffi wrappers |
Direct Win32 C++ Kernel Subsystem |
| Java Preview Flags Required | No | No | No (Zero Preview Flags, Java 21+ LTS) |
| Direct HCURSOR Query | โ Not exposed | โ
Native FastCursor.get() |
|
| Window Class Binding | โ Event-polling only | โ
Native SetClassLongPtrW (HWND) |
|
| Live Cursor Screen Capture | โ None | โ None | โ
Native captureCursor() (ARGB) |
| Frame Alpha Blending | โ Manual CPU loops | โ None | โ
Native blendCursor() (In-Place) |
| Invocation Latency | ~2โ5 ms (EDT dispatch) | ~50โ100 ยตs (JNA boundary) | < 1 ยตs (Direct JNI Dispatch) |
| Preloaded Handle Cache | No | Manual implementation | โ Built-in Concurrent Cache |
- โก Ultra-Fast Native Win32 C++ & JNI Engine: Zero Java Preview Flags, Zero JNA Overhead. Built for seamless integration across all Java 21+ standard runtimes.
- ๐ฏ Thread & Window Scoped Cursors: Instantly switch the active thread cursor or register class-level cursor shapes (
SetClassLongPtrW) perHWNDso Windows applies them natively on hover. - ๐ฅ Live Cursor Capture & Blending: High-speed cursor capture with hot-spot geometry and direct alpha compositing into video or framebuffer arrays via
blendCursor(...). - ๐ Native Handle Inspection: Retrieve the calling thread's active
HCURSORaddress directly viaFastCursor.get(). - ๐ฒ Sub-Microsecond Latency: Built-in concurrent handle caching avoids redundant
LoadCursorWWin32 calls. - ๐ก๏ธ Fail-Safe Fallbacks: Safe native lifecycle with zero JVM crashes, memory leaks, or GC allocations.
- ๐ฎ Desktop Streaming & Capture (FastVideoStream): Real-time cursor alpha blending into video pipelines via
FastCursor.blendCursor(...)without frame jitter. - ๐จ Canvas, Diagramming & CAD (FastGUI): Native resize pointers (
IDC_SIZEWE,IDC_SIZENS,IDC_SIZENWSE,IDC_SIZEALL) that feel 100% native and responsive even during heavy background rendering. - ๐ช Window Hover Feedback (FastWindow): Bind custom cursors per window handle (
setForWindow) for effortless interaction cues. - โณ Background Task Indication: Immediate system spinner (
IDC_WAIT/IDC_APPSTARTING) triggered on the calling thread without EDT queue contention.
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Your Application โ
โ (Editors, Snipping Tools, Canvas, UI) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ fastcursor.FastCursor โ
โ (Facade: set, setForWindow, get, show, hide) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ fastcursor.NativeUser32Cursor โ
โ (Direct JNI Native Dispatch + Cache) โ
โโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโ
โ โ
Direct Native JNI Concurrent Cache
โ (HCURSOR handles)
โผ โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ fastcursor.dll (Native C++ Subsystem) โ
โ โข SetCursor โข LoadCursorW โ
โ โข SetClassLongPtrW โข GetCursor โ
โ โข ShowCursor โข Capture & Alpha Blending โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
CursorType provides full coverage of standard Win32 IDC resource cursor shapes:
import fastcursor.FastCursor;
import fastcursor.CursorType;
// Set wait cursor during background computation
FastCursor.set(CursorType.WAIT);
// Restore default arrow
FastCursor.set(CursorType.ARROW);import fastcursor.FastCursor;
import fastcursor.CursorType;
long hwnd = 0x12345678L; // Native Win32 window handle
// Set hand cursor whenever mouse hovers over this window
FastCursor.setForWindow(hwnd, CursorType.HAND);import fastcursor.FastCursor;
// Get the native HCURSOR handle of the active thread (long address)
long hCursor = FastCursor.get();
System.out.println("Native HCURSOR address: 0x" + Long.toHexString(hCursor));import fastcursor.FastCursor;
// Hide mouse pointer
FastCursor.hide();
// Restore visibility
FastCursor.show();FastCursor is rigorously benchmarked via OpenJDK JMH to guarantee zero JVM allocation and sub-microsecond Win32 dispatch latencies:
| Benchmark / Operation | Throughput (ops/ms) | Ops per Second | Latency |
|---|---|---|---|
benchmarkGetCursorHandle (Direct Win32 GetCursor) |
~2,704 ops/ms | > 2.70 Million | < 370 ns |
benchmarkSetCursorCached (IDC handle resolution + SetCursor) |
~1,642 ops/ms | > 1.64 Million | < 610 ns |
benchmarkSetCursorSwitch (Active shape alternation) |
~1,473 ops/ms | > 1.47 Million | < 680 ns |
Measured on Windows 11 (x64), JDK 21.0.12.1. Native C++ JNI dispatch with 0 bytes GC heap allocation and sub-microsecond latency.
| Case | Java Example | Launcher | Description |
|---|---|---|---|
| Interactive Terminal Demo | Demo.java | run-demo.bat |
Cycles through all Win32 system cursor shapes every 3 seconds directly over the console window. |
| JMH Microbenchmark Suite | Benchmark.java | run-benchmark.bat |
JMH microbenchmark suite measuring Win32 downcall throughput and handle cache performance. |
Add the JitPack repository and the dependency to your pom.xml:
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependencies>
<!-- FastCursor Engine -->
<dependency>
<groupId>com.github.andrestubbe</groupId>
<artifactId>FastCursor</artifactId>
<version>0.1.2</version>
</dependency>
<!-- Required Native Platform Infrastructure -->
<dependency>
<groupId>com.github.andrestubbe</groupId>
<artifactId>FastCore</artifactId>
<version>0.1.0</version>
</dependency>
</dependencies>repositories {
maven { url 'https://jitpack.io' }
}
dependencies {
implementation 'com.github.andrestubbe:FastCursor:0.1.2'
implementation 'com.github.andrestubbe:FastCore:0.1.0'
}Download the latest compiled JARs directly to add them to your classpath:
- ๐ฏ FastCursor-0.1.2.jar (The Core Cursor Engine)
- โ๏ธ FastCore-0.1.0.jar (The Native Platform Loader)
Note
FastCursor 0.1.2+ uses standard JNI (fastcursor.dll loaded automatically via FastCore). No preview flags or JVM arguments are required.
- CHANGELOG.md: Detailed version notes and update history.
- REFERENCE.md: Complete API manual and method signatures.
- PHILOSOPHY.md: The engineering rationale for zero-DLL FFM performance.
- ROADMAP.md: Future milestones and planned features (
.ani/.curcustom cursors). - COMPILE.md: Build and preview flags guide.
| Platform | Architecture | Status | Notes |
|---|---|---|---|
| Windows 10 / 11 | x64 |
โ Fully Supported | Win32 user32.dll via Java 21+ Project Panama FFM |
| Linux (X11 / Wayland) | x64 / AArch64 |
๐ง Planned | X11 XFixes / Wayland Pointer Shape Protocol |
| macOS (Sonoma+) | Apple Silicon / x64 |
๐ง Planned | Cocoa NSCursor / CoreGraphics Direct Pointer API |
- FastCore โ Unified native loader and Project Panama FFM platform runtime.
- FastMouse โ Ultra-low latency native RawInput mouse interception (1,000โ8,000 Hz).
- FastPointer โ Zero-overhead native address arithmetic and memory pointer abstraction.
- FastRobot โ Low-latency native input automation and simulation.
This project is licensed under the MIT License. Part of the FastJava Ecosystem.