Virtual Joystick in Java
Asked Answered
D

2

7

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!

Deforce answered 3/1, 2011 at 23:33 Comment(3)
PPJoy is probably your best bet, but I do hope someone has a better solution for you!Particularly
Thanks, I know it works great. And it's relatively simple to implement in one's C code. But then, it's that I need it in Java :-/Deforce
Maybe, it'll work using JNA or NativeCall instead of JNI. Hmmm.Deforce
D
7

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.

Deforce answered 4/1, 2011 at 14:44 Comment(0)
T
1

I've found this :

http://www.hardcode.de/jxinput/

Not tried yet though. Hope it helps!

Teagan answered 15/1, 2014 at 14:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.