Skip to content

Input4j 🎮 The pure java input library without native binaries.

Notifications You must be signed in to change notification settings

gurkenlabs/input4j

Repository files navigation

Input4j

Input4j is a free and pure Java input library based on the Foreign Function & Memory API (FFM API). This library doesn't have any additional native artifacts and directly interoperates with platform native libraries to access input devices.

⚠ Minimum required Java version: Java 22

The FFM API has been finalized with (JEP 454) with Java 22.

🎮 Main Features

  • Cross-platform support: Works on Windows, Linux, and OSX (in progress).
  • No additional native artifacts: Directly interoperates with platform native libraries.
  • Polling and event-based input: Supports both polling and event-based input mechanisms.
  • Extensible: Easily extendable to support new input devices and platforms.

⚙️ Installation

To use Input4j in your project, add the following dependency to your build.gradle file:

dependencies {
  implementation 'de.gurkenlabs:input4j:1.0.0'
}

💻 Code examples

try (var inputDevices = InputDevices.init()) {
  while (!inputDevices.getAll().isEmpty()) {
    
    // iterate all available input devices and poll their data every second
    for (var inputDevice : inputDevices.getAll()) {
      inputDevice.poll();
      System.out.println(inputDevice.getInstanceName() + ":" + inputDevice.getComponents());
    }

    Thread.sleep(1000);
  }
}

📦 Supported input APIs

  • Windows: DirectInput ✅
  • Windows: XInput ✅
  • Linux: Linux Input (evdev) 🚧
  • OSX: IOKIT ❌
  • OSX: Game Controller ❌

About

Input4j 🎮 The pure java input library without native binaries.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages