Java中的虚拟操纵杆

时间:2011-01-03 23:33:04

标签: java java-native-interface wrapper jna joystick

您是否听说过带有Java包装的Windows虚拟操纵杆?

我正在尝试PPJOY,它的效果很好,但是我需要使用JNI让它从Java开始工作,而且暂时看起来并不容易。

谢谢!

2 个答案:

答案 0 :(得分:6)

你有。我为PPJoy制作了一个Java包装器。它真的很容易使用。参见:

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();
}

可以找到源代码和二进制文件here

答案 1 :(得分:1)

我发现了这个:

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

虽然没有尝试过。希望它有所帮助!