2018-05-23 15:58:39 +02:00
|
|
|
---
|
|
|
|
|
layout: default
|
|
|
|
|
---
|
2018-06-01 17:44:38 +02:00
|
|
|
[](https://maven-badges.herokuapp.com/maven-central/net.java.jinput/coreapi)
|
|
|
|
|
[](http://www.javadoc.io/doc/net.java.jinput/coreapi)
|
2018-05-23 16:20:15 +02:00
|
|
|
|
|
|
|
|
# Welcome to the Java Input API Project!
|
|
|
|
|
|
|
|
|
|
<p>The JInput Project hosts an implementation of an API for game controller
|
|
|
|
|
discovery and polled input. It is part of a suite of open-source technologies
|
|
|
|
|
initiated by the Game Technology Group at Sun Microsystems with intention of
|
|
|
|
|
making the development of high performance games in Java a reality.</p>
|
|
|
|
|
<p>The API itself is pure Java and presents a platform-neutral
|
|
|
|
|
completely portable model of controller discovery and polling.
|
|
|
|
|
It can handle arbitrary controllers and returns both human and
|
|
|
|
|
machine understandable descriptions of the inputs available.</p>
|
|
|
|
|
<p>The implementation hosted here also includes plug-ins to allow
|
|
|
|
|
the API to adapt to various specific platforms. These plug-ins
|
|
|
|
|
often contain a native code portion to interface to the host system.
|
|
|
|
|
</p>
|
|
|
|
|
|
2018-05-23 16:23:36 +02:00
|
|
|
## Getting Started
|
2018-05-23 16:20:15 +02:00
|
|
|
|
|
|
|
|
Include dependency in your project:
|
|
|
|
|
|
|
|
|
|
1. Maven - Easy way
|
|
|
|
|
-----
|
2018-05-23 16:23:36 +02:00
|
|
|
```xml
|
|
|
|
|
<dependency>
|
|
|
|
|
<groupId>net.java.jinput</groupId>
|
|
|
|
|
<artifactId>jinput</artifactId>
|
2018-06-01 18:06:16 +02:00
|
|
|
<version>2.0.9</version>
|
2018-06-01 17:40:35 +02:00
|
|
|
<type>pom</type>
|
2018-05-23 16:23:36 +02:00
|
|
|
</dependency>
|
|
|
|
|
```
|
2018-06-01 17:29:56 +02:00
|
|
|
You'll also need to add the build plugin in your `build/plugins` section of your pom
|
|
|
|
|
```xml
|
2018-06-01 17:40:35 +02:00
|
|
|
<plugin>
|
|
|
|
|
<groupId>com.googlecode.mavennatives</groupId>
|
|
|
|
|
<artifactId>maven-nativedependencies-plugin</artifactId>
|
|
|
|
|
</plugin>
|
2018-06-01 17:29:56 +02:00
|
|
|
```
|
|
|
|
|
|
2018-05-23 16:20:15 +02:00
|
|
|
|
|
|
|
|
2. Build from sources - Experts only
|
|
|
|
|
-----
|
2018-06-01 17:50:20 +02:00
|
|
|
See the readme.md at
|
2018-05-23 16:23:36 +02:00
|
|
|
## Usage
|
2018-05-23 16:20:15 +02:00
|
|
|
|
2018-05-23 16:34:50 +02:00
|
|
|
```java
|
|
|
|
|
/* Create an event object for the underlying plugin to populate */
|
|
|
|
|
Event event = new Event();
|
2018-05-23 16:32:42 +02:00
|
|
|
|
2018-05-23 16:34:50 +02:00
|
|
|
/* Get the available controllers */
|
|
|
|
|
Controller[] controllers = ControllerEnvironment.getDefaultEnvironment().getControllers();
|
|
|
|
|
for (int i = 0; i < controllers.length; i++) {
|
|
|
|
|
/* Remember to poll each one */
|
|
|
|
|
controllers[i].poll();
|
2018-05-23 16:32:42 +02:00
|
|
|
|
2018-05-23 16:34:50 +02:00
|
|
|
/* Get the controllers event queue */
|
|
|
|
|
EventQueue queue = controllers[i].getEventQueue();
|
2018-05-23 16:32:42 +02:00
|
|
|
|
2018-05-23 16:34:50 +02:00
|
|
|
/* For each object in the queue */
|
|
|
|
|
while (queue.getNextEvent(event)) {
|
|
|
|
|
/* Get event component */
|
|
|
|
|
Component comp = event.getComponent();
|
2018-05-23 16:32:42 +02:00
|
|
|
|
2018-05-23 16:34:50 +02:00
|
|
|
/* Process event (your awesome code) */
|
|
|
|
|
...
|
2018-05-23 16:32:42 +02:00
|
|
|
}
|
2018-05-23 16:34:50 +02:00
|
|
|
}
|
|
|
|
|
```
|
2018-05-23 16:32:42 +02:00
|
|
|
|
2018-05-23 16:34:50 +02:00
|
|
|
[More examples here](https://github.com/jinput/jinput/tree/master/examples/src/main/java/net/java/games/input/example).
|