当然,这很粗糙,但它确实有效。键码0xAF
是音量增大的虚拟键。这里有一点 JScript 来发送那个关键代码 50 次。
var shl = new ActiveXObject("WScript.Shell");
for (var i=0; i<50; i++) {
shl.SendKeys(String.fromCharCode(0xAF));
}
您可以使用批处理 + JScript 混合格式将其合并到批处理脚本中。我还对您的脚本进行了一些其他调整,将当前时间退格并重新输出,而不是在每个循环上清除屏幕,使时间比较成为数学比较以允许输入而hh:mm
无需指定秒和厘秒,否则只需在这里和那里进行一些抛光。
@if (@a==@b) @end /*
:: batch portion
@ECHO OFF
setlocal
cls && color 0a
:: capture backspace character to %BS%
for /f %%a in ('"prompt $H&for %%b in (1) do rem"') do set "BS=%%a"
echo Ezlo alarm system
call :gettime now
echo The curent time is: %now%
set /p INPUT=What time should the alarm be set for? (24hr)
echo;
if "%now%" geq "%input%" (set tomorrow=1) else set tomorrow=
if defined tomorrow (
echo Alarm is set for %input% tomorrow.
) else echo Alarm is set for %input%.
set /p "=The curent time is: "<NUL
:time
call :gettime now
set /p "=%now%"<NUL
if "%now%" geq "%INPUT%" (
if not defined tomorrow GOTO ALARM
) else if defined tomorrow set tomorrow=
ping -n 2 0.0.0.0 >NUL
call :len %now% len
for /l %%I in (1,1,%len%) do set /p "=%BS%"<NUL
GOTO time
:ALARM
echo;
ECHO get up!
cscript /nologo /e:jscript "%~f0"
start "" "D:\Users\nic\Desktop\ezlo alarm\alarmtone.mp3"
echo press space to close
PAUSE >nul
color 07
exit /b
:gettime <varname>
set "gtvarnow=%time:~0,-3%"
set "%~1=%gtvarnow: =%"
goto :EOF
:len <string> <varname>
set len=0
set str=%~1
:len_loop
if defined str (
set "str=%str:~1%"
set /a "len+=1"
goto :len_loop
) else set "%~2=%len%"
goto :EOF
:: JScript portion */
var shl = new ActiveXObject("WScript.Shell");
for (var i=0; i<50; i++) {
shl.SendKeys(String.fromCharCode(0xAF));
}
不幸的是,没有简单的方法以编程方式检测系统音量是否已静音。当然,有一个切换静音的关键代码,但没有简单的编程方法来检查它是否需要被触发。如果您需要您的脚本强制系统不静音,最简单的解决方案是使用第三方实用程序,例如NirCmd。有关详细信息,请参阅此答案。