Mat*_*erg 8 windows autohotkey volume windows-10
当在 Windows 上按下增加音量的标准键盘键时,左上角会出现一个小窗口,显示音量以及可能有关播放媒体的信息。我正在寻找一种在不更改音量状态的情况下触发窗口的方法,最好以一种易于与 Autohotkey 集成的方式。
与音量控制键一起使用时所需的行为可以通过存储当前音量、发送媒体键按下、然后将音量更新为存储值 +/- 1(或 +0,如果只是寻求显示 OSD)来获得。
Volume_Down当音量 <=3 时进行模仿时会出现边缘情况。发送的Volume_Down按键会触发静音,但这可以通过手动将静音设置为关闭来解决,或者将音量预先设置为 4,这样可以防止四舍五入到 0。选择哪种方法取决于您是否喜欢当音量从 <=3 值降低时,可能会发出短暂的响亮声音(预设为 4)或短暂静音(之后禁用静音)。
以下代码位于 AHK v2 中。
; Prefix with '$' so as to prevent self triggering, since internally sending Volume_Up
$Volume_Up::{
; Get the current volume. SoundGetVolume returns a float which often needs rounding
volume:=Round(SoundGetVolume())
; Send the Volume_Up key, so the media display is triggered
Send "{Volume_Up}"
; Indiscriminately set the volume manually to volume+1
SoundSetVolume(volume+1)
}
; Much the same as above, yet when sending Volume_Down at volumes <=3 the volume
; is rounded down to 0 which triggers mute. The volume is then set properly,
; yet remains muted. In order to not hear a cut in the audio, you need to set
; the volume to 4 when (1<volume<=3) so that the Volume_Down doesn't round it
; down to 0, or disable the mute afterwards (if volume > 1). This causes a
; brief volume spike or mute blip, respectively. Currently the volume spike option
; is uncommented.
$Volume_Down::{
volume:=Round(SoundGetVolume())
; Bumping the volume before sending the Volume_Down to prevent mute blip (if needed)
if(1 < volume and volume <= 3){
SoundSetVolume(4)
}
Send "{Volume_Down}"
SoundSetVolume(volume-1)
; ; Disable accidental triggering of mute when volume >= 3 after sending Volume_Down
; if(volume > 1) {
; SoundSetMute(0)
; }
}
Run Code Online (Sandbox Code Playgroud)
当问题询问时触发 OSD 可以进行以下操作。按音量键然后快速重置音量将显示它,但如果当前处于静音状态,则需要考虑以防止出现声音。使用音量键是因为双重切换Volume_Mute会导致声音输出出现间隙。
; Trigger the on screen display of the volume bar by hitting Volume_Up and
; then quickly resetting the volume. If muted and send Volume_Up, we will
; hear audio at original volume for a brief second. To prevent this, we
; can set the volume to 0 and send Volume_Down instead.
^PgUp::{
volume:=Round(SoundGetVolume())
muted:=SoundGetMute()
; Trigger the display with a volume key (might briefly bump the volume if unmuted)
if (muted or volume == 0) {
SoundSetVolume(0)
Send "{Volume_Down}"
} else {
Send "{Volume_Up}"
}
; Reset to the original volume and mute status
SoundSetMute(muted)
SoundSetVolume(volume)
}
Run Code Online (Sandbox Code Playgroud)
所有相同的代码,但未注释:
$Volume_Up::{
volume:=Round(SoundGetVolume())
Send "{Volume_Up}"
SoundSetVolume(volume+1)
}
$Volume_Down::{
volume:=Round(SoundGetVolume())
if(1 < volume and volume <= 3){
SoundSetVolume(4)
}
Send "{Volume_Down}"
SoundSetVolume(volume-1)
}
^PgUp::{
volume:=Round(SoundGetVolume())
muted:=SoundGetMute()
if (muted or volume == 0) {
SoundSetVolume(0)
Send "{Volume_Down}"
} else {
Send "{Volume_Up}"
}
SoundSetMute(muted)
SoundSetVolume(volume)
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2382 次 |
| 最近记录: |