Java中的虚拟操纵杆 [英] Virtual Joystick in Java

查看:145
本文介绍了Java中的虚拟操纵杆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你有没有听说过带有Java包装的Windows虚拟操纵杆?

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

我正在尝试PPJOY,它运行良好,但后来我需要使用JNI从Java开始工作,暂时看起来并不容易。

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.

谢谢!

推荐答案

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

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.

这篇关于Java中的虚拟操纵杆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆