當然,這是粗糙的,但它的工作原理。密碼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