当然,这是粗糙的,但它的工作原理。密码0xAF
是一个virtual key音量增加。这里有一些JScript发送密钥代码50次。
var shl = new ActiveXObject("WScript.Shell");
for (var i=0; i<50; i++) {
shl.SendKeys(String.fromCharCode(0xAF));
}
您可以使用批处理+ JScript的混合格式整合到您的批处理脚本这一点。我还对你的脚本做了一些调整,使当前时间退后并重新输出,而不是清除每个循环的屏幕,使时间比较成为一个数学比较,允许输入hh:mm
而不需要指定秒和厘秒,否则只是在这里和那里抛光。
@if (@[email protected]) @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。有关详细信息,请参见this answer。
为什么这个问题标记为[c]和[nul]? – alk 2013-04-10 09:48:46
欢迎来到S.O.如果这是您第一次来这里,请查看[此信息](http://meta.stackexchange.com/a/5235/187716)有关将答案标记为已接受的信息。 – rojo 2013-04-10 13:19:38