The program that the following kotlin code is from is supposed to detect a specific controller and its left joystick using Jinput, and then translate the left joystick's position(for now just the X axis) to a position on the screen and set the cursor to that point. However, despite every source online I could find hinting that my code should work perfectly how it is, it does not detect anything, no matter what I do. It doesn't help that most of what I can find on this topic is around 10 years old and written in Java, so some up-to-date info would really help me out. Here is my code to detect the controller:
import net.java.games.input.Controller
import net.java.games.input.ControllerEnvironment
import java.awt.Point
import java.awt.Robot
import java.awt.Toolkit
fun main(args: Array<String>) {
System.setProperty("net.java.games.input.useDefaultPlugin", "false")
val ce = ControllerEnvironment.getDefaultEnvironment()
val controllers = ce.controllers
if(controllers.isEmpty()) println("no controllers found.")
var leftJoystick: Component? = null
for (controller in controllers) {
println(controller.name)
if (controller.type == Controller.Type.GAMEPAD/* && controller.name.contains("Wireless Controller")*/) {
val components = controller.components
for (component in components) {
if (component.name.contains("X Axis")/* && component.isAnalog*/) {
leftJoystick = component
break
}
}
if (leftJoystick != null) {
break
}
}
}
}
I have added a line to tell me if there are any controllers detected at all:
if(controllers.isEmpty()) println("no controllers found.")
When I run the code, it tells me there are "no controllers found," even though I do have a controller connected. I have tried both via USB and Bluetooth, it still doesn't work. Presumably, it should also be detecting things like my keyboard and mouse, but it's not. I've tried on both windows 10 and 11, same result.
Why can't it detect my controller(which is a PS5 controller)?