广东网站建设联系电话,网站未被百度中收录的原因,番禺人才网官网单位招考,html5是什么目录1、使用 Java 来控制 Windows 系统音量#xff0c;使用 JNA 调用 windows 底层 API 因为有点麻烦#xff0c;所以这里采用纯 Java API结合 VBS 脚本的方式进行控制。2、可以参考《VBS 控制 Windos 系统音量 及视频播放》#xff0c;本文同样是利用 VBS 来控制#xff0…目录1、使用 Java 来控制 Windows 系统音量使用 JNA 调用 windows 底层 API 因为有点麻烦所以这里采用纯 Java API结合 VBS 脚本的方式进行控制。2、可以参考《VBS 控制 Windos 系统音量 及视频播放》本文同样是利用 VBS 来控制区别在于这里的 vbs 文件会用 Java 代码动态生成灵活性更强。Java 控制 Windows 系统音量import java.io.File;import java.io.FileOutputStream;import java.io.IOException;import java.io.OutputStreamWriter;import java.util.logging.Logger;/*** Created by Administrator on 2018/6/26 0026.* 系统工具类*/public class SystemUtils {private static final Logger logger Logger.getGlobal();/*** 控制电脑系统音量* * 约定在应用根目录下的 temp 目录中放置3个vbs文件* volumeMute.vbs用于静音* volumeAdd.vbs增加音量* volumeMinus.vbs减小音量* 文件以及文件的内容采用 Java 代码动态生成不存在时则新建存在时则直接调用** param type 0静音/取消静音 1增加音量 2减小音量*/public static void controlSystemVolume(String type) {try {if (type null || .equals(type.trim())) {logger.info(type 参数为空,不进行操作...);}/**tempFilevbs 文件* vbsMessagevbs 文件的内容*/String vbsMessage ;File tempFile null;Runtime runtime Runtime.getRuntime();switch (type) {case 0:tempFile new File(temp, volumeMute.vbs);vbsMessage !tempFile.exists() ? CreateObject(Wscript.Shell).Sendkeys 棴 : ;break;case 1:tempFile new File(temp, volumeAdd.vbs);vbsMessage !tempFile.exists() ? CreateObject(Wscript.Shell).Sendkeys 棷 : ;break;case 2:tempFile new File(temp, volumeMinus.vbs);vbsMessage !tempFile.exists() ? CreateObject(Wscript.Shell).Sendkeys 棶 : ;break;default:return;}/*** 当3个vbs文件不存在时则创建它们应用默认编码为 utf-8 时创建的 vbs 脚本运行时报错* 于是使用 OutputStreamWriter 将 vbs 文件编码改成gbd就正常了*/if (!tempFile.exists() !vbsMessage.equals()) {if (!tempFile.getParentFile().exists()) {tempFile.getParentFile().mkdirs();}tempFile.createNewFile();FileOutputStream fileOutputStream new FileOutputStream(tempFile);OutputStreamWriter outputStreamWriter new OutputStreamWriter(fileOutputStream, GBK);outputStreamWriter.write(vbsMessage);outputStreamWriter.flush();outputStreamWriter.close();logger.info(vbs 文件不存在新建成功 tempFile.getAbsolutePath());}runtime.exec(wscript tempFile.getAbsolutePath()).waitFor();logger.info(音量控制完成.);} catch (IOException e) {e.printStackTrace();} catch (InterruptedException e) {e.printStackTrace();}}public static void main(String[] args) throws InterruptedException {logger.info(1 秒后开始静音.);Thread.sleep(1000);controlSystemVolume(0);logger.info(1 秒后开始取消静音.);Thread.sleep(1000);controlSystemVolume(0);logger.info(1 秒后开始增加 2 格音量可以使用循环持续增加音量.);Thread.sleep(1000);controlSystemVolume(1);logger.info(1 秒后开始减小音量可以使用循环持续减小.);Thread.sleep(1000);for (int i 0; i 3; i) {controlSystemVolume(2);Thread.sleep(500);}}}