I'm attempting to make a program in Kotlin for a JVM application that takes PlayStation 5 controller input from the left joystick only and sets the cursor position on screen to the position of the joystick. For example, if I move the joystick 75% to the left and 50% up, the cursor would move to the coordinates that are 75% between the center and left edge, and halfway between the center and top edge of the screen. Because AI is so useful, I've actually been using an AI to assist me with this project, and its surprisingly useful, but it can't help with everything, and I'm unsure how to proceed in fixing my current issue.
I attempted to test run my code in Injellij IDEA, but it failed, giving a couple of UnsatisfiedLinkError
errors. There's also a couple other flaws and suspicions I have with the code, and I'll solve those issues when I know they're real issues, but if anyone can spot these issues and suggest a fix, I'd appreciate it too. Here is my code:
import net.java.games.input.Component
import net.java.games.input.Controller
import java.awt.Robot
import java.awt.Toolkit
import net.java.games.input.ControllerEnvironment
fun main(args: Array<String>) {
// Get input from the left joystick
val joystickInput = getJoystickInput()
// Get the size of the screen
val screenWidth = Toolkit.getDefaultToolkit().screenSize.width
val screenHeight = Toolkit.getDefaultToolkit().screenSize.height
// Map the joystick's X-value to the cursor's X-coordinate
val cursorX = (joystickInput.x * screenWidth).toInt()
// Map the joystick's Y-value to the cursor's Y-coordinate
val cursorY = (joystickInput.y * screenHeight).toInt()
// Set the position of the cursor on the screen to the joystick's position.
setCursorPosition(cursorX, cursorY)
}
fun getJoystickInput(): JoystickInput {
// Get the default controller
val controller = ControllerEnvironment.getDefaultEnvironment().getControllers().firstOrNull { it.type == Controller.Type.STICK } ?: return JoystickInput(0f, 0f)
// Poll the controller for input data
controller.poll()
// Get the X & Y values of the joystick axis
val xAxisValue = controller.getComponent(Component.Identifier.Axis.X).pollData
val yAxisValue = controller.getComponent(Component.Identifier.Axis.Y).pollData
// Convert the joystick values to a range from -1 to 1 | Note that I will need to change the range to from 0 to 1 later. The AI wrote this part, I'll make these tweaks once I've successfully test ran the program.
val x = (xAxisValue - 0.5f) * 2f
val y = (yAxisValue - 0.5f) * 2f
// Return the joystick input as a JoystickInput object
return JoystickInput(x, y) // I probably dont need it to be like this, it looks like x and y will always be identical. I created the data class JoystickInput assuming I would need separate x and y values, but the AI that I had help from wrote this code segment as if it only need one number.
}
data class JoystickInput(var x: Float, var y: Float)
fun setCursorPosition(cX: Int, cY: Int) {
// Set the cursor position to cursorX, cursorY
Robot().mouseMove(cX, cY)
}
Here is the log giving the error details:
Feb 20, 2023 2:13:44 PM net.java.games.input.DefaultControllerEnvironment getControllers
WARNING: Found unknown Windows version: Windows 11
Feb 20, 2023 2:13:44 PM net.java.games.input.DefaultControllerEnvironment getControllers
WARNING: Attempting to use default windows plug-in.
java.lang.UnsatisfiedLinkError: no jinput-dx8_64 in java.library.path: C:\Users\Owner\Downloads\jdk-17_windows-x64_bin\jdk-17.0.4\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\Program Files\Common Files\Oracle\Java\javapath;C:\Program Files\Eclipse Foundation\jdk-16.0.2.7-hotspot\bin;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\Razer Chroma SDK\bin;C:\Program Files\Razer Chroma SDK\bin;C:\Program Files (x86)\Razer\ChromaBroadcast\bin;C:\Program Files\Razer\ChromaBroadcast\bin;C:\Program Files\AdoptOpenJDK\jre-8.0.275.1-hotspot\bin;C:\Program Files\AdoptOpenJDK\jre-11.0.9.11-hotspot\bin;C:\Program Files (x86)\AdoptOpenJDK\jre-8.0.275.01-hotspot\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Program Files (x86)\Windows Live\Shared;C:\Windows\system32\config\systemprofile\AppData\Local\Microsoft\WindowsApps;C:\Program Files\WorldPainter;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\dotnet\;C:\Program Files\Git\cmd;C:\Users\Owner\AppData\Local\Microsoft\WindowsApps;C:\Users\Owner\AppData\Local\GitHubDesktop\bin;;C:\Users\Owner\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\Owner\.dotnet\tools;.
at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2429)
at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:818)
at java.base/java.lang.System.loadLibrary(System.java:1989)
at net.java.games.input.DirectInputEnvironmentPlugin.lambda$loadLibrary$0(DirectInputEnvironmentPlugin.java:73)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:318)
at net.java.games.input.DirectInputEnvironmentPlugin.loadLibrary(DirectInputEnvironmentPlugin.java:67)
at net.java.games.input.DirectInputEnvironmentPlugin.<clinit>(DirectInputEnvironmentPlugin.java:98)
at net.java.games.input.DirectAndRawInputEnvironmentPlugin.<init>(DirectAndRawInputEnvironmentPlugin.java:45)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
at net.java.games.input.DefaultControllerEnvironment.getControllers(DefaultControllerEnvironment.java:134)
at MainKt.getJoystickInput(Main.kt:29)
at MainKt.main(Main.kt:10)
java.lang.UnsatisfiedLinkError: no jinput-raw_64 in java.library.path: C:\Users\Owner\Downloads\jdk-17_windows-x64_bin\jdk-17.0.4\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\Program Files\Common Files\Oracle\Java\javapath;C:\Program Files\Eclipse Foundation\jdk-16.0.2.7-hotspot\bin;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\Razer Chroma SDK\bin;C:\Program Files\Razer Chroma SDK\bin;C:\Program Files (x86)\Razer\ChromaBroadcast\bin;C:\Program Files\Razer\ChromaBroadcast\bin;C:\Program Files\AdoptOpenJDK\jre-8.0.275.1-hotspot\bin;C:\Program Files\AdoptOpenJDK\jre-11.0.9.11-hotspot\bin;C:\Program Files (x86)\AdoptOpenJDK\jre-8.0.275.01-hotspot\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Program Files (x86)\Windows Live\Shared;C:\Windows\system32\config\systemprofile\AppData\Local\Microsoft\WindowsApps;C:\Program Files\WorldPainter;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\dotnet\;C:\Program Files\Git\cmd;C:\Users\Owner\AppData\Local\Microsoft\WindowsApps;C:\Users\Owner\AppData\Local\GitHubDesktop\bin;;C:\Users\Owner\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\Owner\.dotnet\tools;.
at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2429)
at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:818)
at java.base/java.lang.System.loadLibrary(System.java:1989)
at net.java.games.input.RawInputEnvironmentPlugin.lambda$loadLibrary$0(RawInputEnvironmentPlugin.java:73)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:318)
at net.java.games.input.RawInputEnvironmentPlugin.loadLibrary(RawInputEnvironmentPlugin.java:67)
at net.java.games.input.RawInputEnvironmentPlugin.<clinit>(RawInputEnvironmentPlugin.java:98)
at net.java.games.input.DirectAndRawInputEnvironmentPlugin.<init>(DirectAndRawInputEnvironmentPlugin.java:46)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
at net.java.games.input.DefaultControllerEnvironment.getControllers(DefaultControllerEnvironment.java:134)
at MainKt.getJoystickInput(Main.kt:29)
at MainKt.main(Main.kt:10)
Feb 20, 2023 2:13:44 PM net.java.games.input.ControllerEnvironment log
INFO: net.java.games.input.DirectAndRawInputEnvironmentPlugin is not supported
Process finished with exit code 0
How should I proceed with fixing this error?