最佳答案
正如其他人所说,没有任何官方API可供使用.但是,使用Windows Powershell(我相信它附带的Windows,因此无需下载任何内容)和WmiSetBrightness,可以创建一个简单的解决方法,适用于所有带签证或以后安装的Windows PC.
您需要做的就是将此类复制到您的工作区:
@H_404_12@import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class BrightnessManager { public static void setBrightness(int brightness) throws IOException { //Creates a powerShell command that will set the brightness to the requested value (0-100),after the requested delay (in milliseconds) has passed. String s = String.format("$brightness = %d;",brightness) + "$delay = 0;" + "$myMonitor = Get-WmiObject -Namespace root\\wmi -Class WmiMonitorBrightnessMethods;" + "$myMonitor.wmisetbrightness($delay,$brightness)"; String command = "powershell.exe " + s; // Executing the command Process powerShellProcess = Runtime.getRuntime().exec(command); powerShellProcess.getOutputStream().close(); //Report any error messages String line; BufferedReader stderr = new BufferedReader(new InputStreamReader( powerShellProcess.getErrorStream())); line = stderr.readLine(); if (line != null) { System.err.println("Standard Error:"); do { System.err.println(line); } while ((line = stderr.readLine()) != null); } stderr.close(); } }
然后打电话
@H_404_12@BrightnessManager.setBrightness({brightness});