Virtual Joystick in Java

﹥>﹥吖頭↗ 提交于 2019-12-21 04:30:15

问题


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!


回答1:


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.




回答2:


I've found this :

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

Not tried yet though. Hope it helps!



来源:https://stackoverflow.com/questions/4589380/virtual-joystick-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!