Skip to content

Instantly share code, notes, and snippets.

@Hasufel
Created April 27, 2014 00:30
Show Gist options
  • Save Hasufel/11334707 to your computer and use it in GitHub Desktop.
Save Hasufel/11334707 to your computer and use it in GitHub Desktop.
getting controllers
private function getControllers():Void {
var a = JNI.createStaticMethod ("org.haxe.lime.MainView", "getControllersList", "()Ljava/lang/String;", true);
var b:String = a();
var c:Array<String> = b.split(';');
_controllers = new Array<Array<String>>();
var i:Int = 0;
while(i < c.length) {
if (Std.parseInt(c[i])!=null) {
_controllers.push([c[i], c[i+1]]);
}
i+=2;
}
}
public static String getControllersList() {
int[] devices = InputDevice.getDeviceIds();
ArrayList<String> controllerDevices = new ArrayList<String>();
for (int i = 0; i < devices.length; i++) {
InputDevice mDevice = InputDevice.getDevice(devices[i]);
int numAxes = 0;
for (InputDevice.MotionRange range : mDevice.getMotionRanges()) {
if ((range.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) {
numAxes += 1;
}
}
if (numAxes>0) {
controllerDevices.add(Integer.toString(devices[i]));
controllerDevices.add(mDevice.getName());
}
}
String c = "";
int j = 0;
for (String i : controllerDevices){
c+=i;
j++;
if (j < controllerDevices.size()) {
c+=";";
}
}
return c;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment