java - Java 中的虚拟操纵杆

标签 java java-native-interface wrapper jna joystick

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

我正在尝试 PPJOY,它工作得很好,但是我需要使用 JNI 让它在 Java 中工作,目前看来这并不容易。

谢谢!

最佳答案

你来了。我为 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 .

关于java - Java 中的虚拟操纵杆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4589380/

相关文章:

java - 多线程java图像阈值处理

java - SQL语句大概运行,没有错误,但断言失败

java - Android 在发出多个 http 请求时增加堆 fragment 情况

c++ - 我可以基于 char* 而不是文件创建 std::ifstream 吗?

android - 原生android库编译

java - Java 包装类真的是不可变的吗?

java - 为什么内部类 TreeMap.Entry<K,V> 是通用的?

java - 如何在 jni 输入参数中返回 double[]

c - 是否有像 gccxml 这样的用于包装器生成的 C header 解析器工具?

c# - 创建简单的 c++.net 包装器。一步步