Was playing around with JNA and ended up writing a library for joystick/joypads.
This currently only works on Windows OS.
It uses the windows winmm.dll to read the joysticks
It was compiled with Java 8. Also you will need to find copy of jna-3.1.0.jar I have not included it, as I am not sure of the licencing on it.
The library (JoyPad) can give you (on a ps3 controller for example) the dpad, left and right joysticks and the buttons.
It handles multi joystick as in left and right joystick on the controller, and as many buttons as you can press at once.
There is a demo B4j project that just displays the values read from the joypad.
There are 3 routines.
1, Initialize routine - JoyPadInit (no parameters)
2, readJoystick() - this takes one int parameter, the joypad/stick to read.
3, unloadDLL - this unloads the DLL (winmm) probably not a good idea to do while using the library.
I have only one joypad so cannot test how two perform together, but I suspect it is safer to make two joypad entries, one for each joypad.
ie,
Then use joypad1.readJoystick(0) and joypad2.readJoystick(1) etc
I may try and find how to get it to work on mac and linux too.
Added joystickdemo2 - moves a circle around the screen under joystick control.
Added joystickdemo3 - similar to joystickdemo2 but shows how to handle button presses.
Added the wrapper so others can see how to access system .dll's
This currently only works on Windows OS.
It uses the windows winmm.dll to read the joysticks
It was compiled with Java 8. Also you will need to find copy of jna-3.1.0.jar I have not included it, as I am not sure of the licencing on it.
The library (JoyPad) can give you (on a ps3 controller for example) the dpad, left and right joysticks and the buttons.
It handles multi joystick as in left and right joystick on the controller, and as many buttons as you can press at once.
There is a demo B4j project that just displays the values read from the joypad.
There are 3 routines.
1, Initialize routine - JoyPadInit (no parameters)
2, readJoystick() - this takes one int parameter, the joypad/stick to read.
3, unloadDLL - this unloads the DLL (winmm) probably not a good idea to do while using the library.
I have only one joypad so cannot test how two perform together, but I suspect it is safer to make two joypad entries, one for each joypad.
ie,
B4X:
private joypad1 AS JoyPad
private joypad2 AS JoyPad
I may try and find how to get it to work on mac and linux too.
Added joystickdemo2 - moves a circle around the screen under joystick control.
Added joystickdemo3 - similar to joystickdemo2 but shows how to handle button presses.
Added the wrapper so others can see how to access system .dll's
Attachments
Last edited: