2011-01-03 11 views
7

Haben Sie schon einmal von einem virtuellen Joystick für Windows mit Java-Wrappings gehört?Virtueller Joystick in Java

Ich habe versucht PPJOY, und es funktioniert gut, aber dann muss ich JNI verwenden, um es von Java arbeiten zu bekommen, und das scheint vorerst nicht einfach.

Danke!

+1

PPJoy ist wahrscheinlich Ihre beste Wette, aber ich hoffe, jemand hat eine bessere Lösung für Sie! – Brad

+0

Danke, ich weiß * es funktioniert super. Und es ist relativ einfach in seinem C-Code zu implementieren. Aber dann ist es, dass ich es in Java brauche: -/ –

+0

Vielleicht funktioniert es mit JNA oder NativeCall statt JNI. Hmmm. –

Antwort

6

Da sind Sie. Ich habe einen Java Wrapper für PPJoy gemacht. Und es ist wirklich einfach zu bedienen. Siehe:

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

Der Quellcode und Binaries here gefunden werden kann.