GamepadUser Guide

Gamepad is a support library that aids Alien-Factory in the development of other libraries, frameworks and applications. Though you are welcome to use it, you may find features are missing and the documentation incomplete.


The Gamepad library lets you receive input data and events from USB connected gamepads.

Those who play XBox or Playstation are aware that the controllers are USB connected, but did you know you they also work on laptops and PCs!?

Well, they do!

Gamepad controllers are Human Input Devices (HID) over USB. This library wraps the Pure Java HID-API library to provide gamepad support in Fantom.

Quick Start

  1. Create a text file called
    using concurrent::Actor
    class Example {
        Void main() {
            // list all available HID devices
            Gamepad.listHidDevices.each { echo("${it.vendorId.toHex(4)} ${it.productId.toHex(4)} $it") }
            // select any gamepad
            gamepad := Gamepad.listGamepads.first
            if (gamepad == null)
                return echo("No Gamepad detected")
            echo("\nSelected: ${gamepad.prodcutDesc}\n")
            // print which buttons are pressed
            gamepad.onInput = |GamepadEvent event| {
                if (event.buttonsDown.size > 0)
  2. Run as a Fantom script from the command line:
    C:\> fan
    045e 028e XBOX 360 For Windows (Controller)
    04d9 010b USB Keyboard
    04d9 010b USB Keyboard
    04d9 010b USB Keyboard
    0e8f 310d GAMEPAD 3 TURBO
    1532 0013 Razer Orochi
    1532 0013 Razer Orochi
    Selected: XBOX 360 For Windows (Controller)


The standard controller button layout is as follows:

Generic Controller Layout

Only the following controllers are currently supported out of the box:

Vendor ID

Product ID

Product Description



XBOX 360 For Windows (Controller)





Gamepad comes bundled with the following jars:

  • jna-4.2.1.jar
  • purejavahidapi-0.0.10.jar

Later versions of Gamepad may brake the .jars out into their own pods, but for now they're exploded into afGamepad.pod.

Note that due to how pureJavaHidApi is compiled, Gamepad is only compatible with JDK 8 or later.


Note that the following controllers do not register as USB HID devices and hence are not compatible with the Gamepad library:

  • Official XBox One Wireless Controller


  • Add built-in support for more controllers
  • Create controller mapping contributions
  • Create a Javascript implementation. Oh yes! Did you not know of the W3C Gamepad Specification!?