当在Windows上按下标准键盘增加音量的键时,会出现一个小窗口在左上角显示音量以及可能有关正在播放媒体的信息。我正在寻找一种方法来触发该窗口而不改变音量状态,最好能够轻松地与Autohotkey集成。
当在Windows上按下标准键盘增加音量的键时,会出现一个小窗口在左上角显示音量以及可能有关正在播放媒体的信息。我正在寻找一种方法来触发该窗口而不改变音量状态,最好能够轻松地与Autohotkey集成。
Windows 8引入了MediaControl class,允许现代应用程序连接到系统播放控制。在Windows 8.1和10中,它被SystemMediaTransportControls class所取代。
虽然它支持“手动控制系统媒体传输控件”,但似乎没有一种方法可以显示/隐藏叠加层,特别是不能从桌面应用程序中实现。
在未记录的领域中,我找到了叠加层的类名,从而找到了HideVolumeOSD。不幸的是,类名相当通用,因此您可能还需要查看窗口的大小才能确定是否为音量叠加层。
我不知道只是显示窗口是否有效,Windows不希望它可见,除非响应键盘和播放事件。HideVolumeOSD应用程序使用keybd_event
(音量增加/减少)来触发它,但正如评论中所指出的那样,这会有问题...
我设置了一个AutoHotkey脚本,用于发送音量增加和音量减小的命令(使用快捷键ctrl+pgdn)。
^PgDn::
Send {Volume_Up}
Send {Volume_Down}
return
; 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)
; }
}
如问题所问,只需按以下步骤触发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)
}
$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)
}
在Anna Wang的回答(https://dev59.com/yqPia4cB1Zd3GeqP5OLp#62012058)的基础上进行构建。
即使音量值为奇数,这将恢复该音量。
^PgDn:: ;Ctrl+Page Down
SoundGet, original_volume
SendInput {Volume_Down}
SoundSet, original_volume
return