Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Virtual Joystick in Java

Have you heard of a virtual joystick for Windows that has Java wrappings?

I've trying PPJOY, and it works great, but then I'll need to use JNI to get it working from Java and that doesn't seem easy for the time being.

Thanks!

like image 552
Albus Dumbledore Avatar asked Jan 03 '11 23:01

Albus Dumbledore


1 Answers

There you are. I've made a Java wrapper for PPJoy. And it's really easy to use. See:

try {
    /*
     * Try to create a new joystick.
     */
    Joystick joystick = new Joystick();

    try {
        /*
         * Set joystick values
         */

        /*
         * Set analog values for Axis X/Y/Z,
         * Rotation X/Y/Z, Slider, Dial. Overall 8 axes.
         * 
         * Here we set the Z Axis to maximum.
         */
        joystick.analog[Joystick.ANALOG_AXIS_Z] = Joystick.ANALOG_MAX;

        /*
         * Set digital values for the buttons. Overall 16 buttons.
         *
         * Here we turn on the 13-th button
         */
        joystick.digital[12] = Joystick.DIGITAL_ON;

        /*
         * Send the data to the joystick. Keep in mind,
         * that the send method may throw a JoystickException
         */
        joystick.send();
    } finally {
        joystick.close();
    }
} catch (JoystickException e) {
    e.printStackTrace();
}

The source code and binaries may be found here.

like image 185
Albus Dumbledore Avatar answered Sep 29 '22 04:09

Albus Dumbledore