最佳答案
正如其他人所说,没有任何官方API可供使用.但是,使用Windows Powershell(我相信它附带的Windows,因此无需下载任何内容)和WmiSetBrightness,可以创建一个简单的解决方法,适用于所有带签证或以后安装的Windows PC.
您需要做的就是将此类复制到您的工作区:
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();
}
}
然后打电话
BrightnessManager.setBrightness({brightness});
其中{brightness}是要设置屏幕显示的亮度,0为最暗支持亮度,100为最亮.
非常感谢anquegi为PowerShell代码找到here,我适合运行此命令.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。