Skip to the content.

🎮 input4j

A lightweight, cross-platform Java library for unified input device handling.

✨ Features

🚦 Getting Started

Add input4j to your Java project and start handling input devices easily.

💡 Example

InputDevices.update();
for (InputDevice device : InputDevices.getAll()) {
    System.out.println(device.getName());
}

🆚 Advantages over traditional Java input libraries

Input4j leverages the new Foreign Function & Memory API (FFM API) instead of JNI, offering:

📦 Installation

Add the following to your build.gradle:

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

⚡ Quick Start Guide

🔄 Manually Polling and Reading Input Data

try (var inputDevices = InputDevices.init()) {
  while (!inputDevices.getAll().isEmpty()) {
    for (var inputDevice : inputDevices.getAll()) {
      inputDevice.poll();
      System.out.println(inputDevice.getInstanceName() + ":" + inputDevice.getComponents());
    }
    Thread.sleep(1000);
  }
}

📨 Event-Based Input Handling

try (var devices = InputDevices.init()) {
  var device = devices.getAll().stream().findFirst().orElse(null);
  if (device == null) {
    System.out.println("No input devices found.");
    return;
  }
  device.onInputValueChanged(e -> System.out.println("Value changed: " + e.component() + " -> " + e.newValue()));
  device.onButtonPressed(XInput.X, () -> System.out.println("X button pressed"));
  device.onAxisChanged(Axis.AXIS_X, value -> System.out.println("X axis: " + value));
  while (true) {
    device.poll();
    Thread.sleep(1000);
  }
}

🚀 Technical Details

🖥️ System Requirements

📝 Details about the Project

Input4j is a modern, open-source Java library designed to simplify and unify input device management for desktop applications and games. With Input4j, developers can easily access and handle a wide range of input devices such as gamepads, joysticks, and controllers across multiple platforms. The library is built for high performance and reliability, making it ideal for both professional and hobbyist Java developers who want seamless input integration without the hassle of native dependencies.

Input4j stands out due to its use of the latest Java technologies, including the Foreign Function & Memory API (FFM API), ensuring compatibility with current and future Java versions. Its intuitive API, cross-platform support, and focus on safety and speed make it the best choice for anyone looking to add robust input support to their Java projects. Whether you are developing a game, simulation, or any interactive application, Input4j provides the tools you need for responsive and flexible input handling.


Powered by LITIENGINE