Skip to content

About

🖊️ Native stylus input for Java — real WM_POINTER pen events with pressure, tilt, rotation, eraser detection, barrel buttons, hover sensing, and low‑latency hardware access for Surface, Wacom, and Windows Ink devices.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

FastStylus 0.1.0 [ALPHA-2026-05-23] — Ultra-Fast Native Windows Stylus & Pen Input Engine for Java

Status License: MIT Java Platform JitPack


⚡ High-speed Win32 WM_POINTER stylus digitizer interception, pressure tracking, tilt angles, and eraser detection for Java.

FastStylus provides hardware-level stylus and pen access directly from the Win32 Pointer API (WM_POINTER), bypassing the single-cursor mouse emulation limitations of standard AWT and Swing. Capture 10-bit raw pressure (0..1024), dual-axis tilt angles (-90°..+90°), continuous rotation, barrel buttons, and hardware eraser state with minimal latency.

FastStylus Showcase


Quick Start

import faststylus.FastStylus;
import javax.swing.JFrame;

public class Demo {
    public static void main(String[] args) {
        JFrame frame = new JFrame("FastStylus Demo");
        frame.setSize(1280, 800);
        frame.setVisible(true);

        // 1. Initialize native stylus interception on the target window
        FastStylus stylus = FastStylus.create(frame);

        // 2. Add real-time stylus listener
        stylus.addListener(event -> {
            System.out.printf("[STYLUS] ID=%d Pos=(%d,%d) Pressure=%d%% Tilt=(%d,%d) Eraser=%s Phase=%s\n",
                event.id, event.x, event.y, event.pressurePercent, event.tiltX, event.tiltY, event.isEraser, event.state);
        });

        // 3. Start background polling thread (~120 Hz)
        stylus.start();
    }
}

Table of Contents


Why FastStylus?

Standard Java input subsystems (AWT MouseListener, JavaFX, Swing) treat digitizers and pens as generic single-cursor mouse emulations:

  1. Single-Cursor Emulation: Standard AWT discards pen pressure, tilt angles, and barrel button modifiers, treating active digitizers as blunt mice.
  2. Missing Sensor Geometry: Physical force levels (0..1024), dual-axis tilt (-90°..+90°), and barrel rotation (0..360°) are completely lost in pure Java.
  3. Event Queue Delays: Synthesized mouse events pass through the Event Dispatch Thread (EDT), creating noticeable stroke lag during drawing or handwriting.
  4. Legacy Driver Lock-In: Alternative solutions rely on deprecated 1990s Wintab 32-bit DLLs that fail on modern Windows Ink devices and Microsoft Surface hardware.

FastStylus bridges directly to the modern Win32 WM_POINTER digitizer subsystem:

  • Hardware Pressure & Tilt: Full 0–1024 raw pressure levels (mapped to 0–100%) and continuous dual-axis tilt tracking.
  • Eraser & Invert Sensing: Automatic detection when the stylus is physically flipped to the eraser end.
  • Sub-Millisecond Event Loop: Direct window subclassing captures digitizer messages before JVM event queue scheduling.
  • Universal Hardware Support: Native out-of-the-box support for Windows Ink, Microsoft Surface, and Wacom AES/EMR digitizers.
Feature Java AWT / Swing Legacy Wintab Wrappers FastStylus
Input Subsystem Synthesized WM_MOUSEMOVE Legacy Wintab DLL (Wacom only) Native Win32 WM_POINTER
Pressure Tracking ❌ Binary click only (0/1) ⚠️ Driver-dependent ✅ 10-bit raw resolution (0–1024)
Tilt & Rotation ❌ Discarded ⚠️ Inconsistent support ✅ Dual-axis (±90°) + 360° rotation
Eraser / Invert Detection ❌ None ⚠️ Unreliable ✅ Native hardware tip inversion
Event Dispatch Latency 15–30 ms (EDT queue lag) 5–15 ms < 0.1 ms (Direct window subclassing)
Device Compatibility Generic mouse fallback Wacom desktop tablets only Surface, Windows Ink, Wacom AES/EMR

Key Features

  • 🖊️ Hardware Pressure Tracking — Full 10-bit raw resolution (0–1024 levels, normalized 0–100%).
  • 📐 Dual-Axis Tilt & Rotation — Precise X/Y tilt angles (-90° to +90°) and continuous 360° barrel rotation.
  • 🔄 Automatic Eraser & Invert Detection — Native recognition of inverted pens and hardware eraser tips.
  • 🔘 Dual Barrel Buttons — Instant detection of barrel side switches (BTN1, BTN2).
  • 🛸 Proximity Hover Sensing — Track cursor coordinates while the pen hovers above the screen without contact.
  • ⚡ Zero-Copy JNI Architecture — Continuous event dispatch with zero garbage collection churn.

🖊️ Compatible Devices

  • Microsoft Surface Pro 8/9, Studio, Go, Laptop (with Surface Pen)
  • Wacom Penabled, AES, and EMR devices
  • Windows Ink compatible pens
  • HP, Dell, Lenovo 2-in-1 devices with active pens

✅ Tested Devices

Device Pen Pressure Tilt Eraser Barrel Status
Surface Pro 8 Wacom Bamboo Ink Plus ✅ 0-1024 ✅ ±90° ✅ ✅ 2 buttons ✅ Verified Apr 2026

Performance Benchmarks

FastStylus is measured using JMH (Java Microbenchmark Harness) to ensure zero-overhead event processing:

Benchmark / Operation Score (ops/ms) Ops per Second
benchmarkStylusEventAllocation ~19,400 ops/ms > 19.4 Million
benchmarkStylusEventFormatting ~1,520 ops/ms > 1.52 Million
Native Polling Loop Rate ~120 Hz Smooth Real-time Tracking

Measured on Windows 11 (x64), JDK 21+.


API Quick Reference

Method Return Type Description Docs
FastStylus.create(frame) FastStylus Resolves window HWND and installs native WM_POINTER subclass hook. Reference
addListener(listener) void Registers a callback for real-time stylus event dispatch. Reference
removeListener(listener) void Unregisters a previously registered stylus listener. Reference
start() void Launches the dedicated background stylus polling thread (~120 Hz). Reference
stop() void Halts the background stylus polling loop. Reference
FastStylus.isStylusAvailable() boolean Queries if a physical stylus or active digitizer is present. Reference
FastStylus.getMaxStylusPoints() int Returns maximum simultaneous pens supported by hardware. Reference

Technical Demos & Benchmarks

Case Java Example Launcher Description
Interactive Pen HUD & Canvas Demo.java run-demo.bat Real-time drawing canvas with pressure-width scaling, tilt circle HUD, and eraser mode.
JMH Microbenchmark Suite Benchmark.java run-benchmark.bat Microbenchmark suite profiling stylus event allocation and formatting throughput.

Installation

Option 1: Maven (Recommended)

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>
    <!-- FastStylus Library -->
    <dependency>
        <groupId>com.github.andrestubbe</groupId>
        <artifactId>FastStylus</artifactId>
        <version>0.1.0</version>
    </dependency>
    <!-- Required Native JNI loader -->
    <dependency>
        <groupId>com.github.andrestubbe</groupId>
        <artifactId>FastCore</artifactId>
        <version>0.1.0</version>
    </dependency>
</dependencies>

Option 2: Gradle (via JitPack)

repositories {
    maven { url 'https://jitpack.io' }
}

dependencies {
    implementation 'com.github.andrestubbe:FastStylus:0.1.0'
    implementation 'com.github.andrestubbe:FastCore:0.1.0'
}

Option 3: Direct Download (No Build Tool)

Download the latest JARs directly to add them to your classpath:

  1. 📦 FastStylus-0.1.0.jar (The Core Library with embedded native DLL)
  2. ⚙️ fastcore-0.1.0.jar (The Mandatory Native Loader)

Important

All JARs must be in your classpath for the JNI calls to function correctly.


Documentation

  • COMPILE.md: Full compilation guide (MSVC C++17 build chain + JNI Setup).
  • REFERENCE.md: Comprehensive API specification, event fields, and hook lifecycle.
  • PHILOSOPHY.md: The engineering rationale for hardware-native pen interception.
  • ROADMAP.md: Planned milestone features and performance extensions.
  • CHANGELOG.md: Complete version history and release notes.

Platform Support

Platform Architecture Status Driver / Subsystem
Windows 10 / 11 x64 ✅ Fully Supported Native Win32 WM_POINTER Subsystem
Linux x64 / AArch64 🚧 Planned libinput / evdev Stylus Tablet Tool Slots
macOS Apple Silicon / x64 🚧 Planned NSEvent & TabletProximity / CoreGraphics

Related Projects

  • FastCore — Native Library Loader & JNI Utilities for Java
  • FastTouch — Native Multi-Touch Digitizer API for Java
  • FastMouse — Ultra-Low Latency Native RawInput Mouse Engine
  • FastKeyboard — Ultra-Fast Native RawInput Keyboard Engine
  • FastHotkey — Low-Latency Global Hotkey API for Java
  • FastVulkan — High-Performance Native Vulkan 2D Rendering Engine

License

MIT License — See LICENSE file for details.


Part of the FastJava Ecosystem — Making the JVM faster. 🚀

About

🖊️ Native stylus input for Java — real WM_POINTER pen events with pressure, tilt, rotation, eraser detection, barrel buttons, hover sensing, and low‑latency hardware access for Surface, Wacom, and Windows Ink devices.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages