2011-01-03 26 views
7

¿Has oído hablar de un joystick virtual para Windows que tiene envoltorios de Java?Joystick virtual en Java

He intentado con PPJOY, y funciona muy bien, pero luego necesitaré usar JNI para hacerlo funcionar desde Java y eso no parece fácil por el momento.

Gracias!

+1

PPJoy es probablemente su mejor opción, pero espero que alguien tenga una mejor solución para usted. – Brad

+0

Gracias, sé * que funciona muy bien. Y es relativamente simple de implementar en el código C de uno. Pero entonces, es que lo necesito en Java: -/ –

+0

Tal vez funcione con JNA o NativeCall en lugar de JNI. Hmmm. –

Respuesta

6

Ahí lo tienes. He creado un contenedor Java para PPJoy. Y es realmente fácil de usar. Ver:

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

El código fuente y los binarios pueden encontrarse here.

Cuestiones relacionadas