正如标题所说,我希望能够让 Windows Media Player 在锁定我的电脑时暂停,并在解锁后再次播放。
这可能吗?
我确实尝试使用这个 AutoHotKey 脚本来做到这一点:
;---------------------------------------------------------------
;Notify Lock\Unlock
; This script monitors LockWorkstation calls
;
; If a change is detected it 'notifies' the calling script
; On Lock
; This script will call function "on_lock()"
; On Unlock
; This script will call fucntion "on_unlock()"
;IMPORTANT: The functions "on_lock()" and "on_unlock()" DO NOT
;exist in this script, they are to be created in the script that
;calls notify_lock_unlock() (presumably your main script)
;---------------------------------------------------------------
;Re-purposed by WTO605
;Last edited 2009-08-18 16:34 UTC
;---------------------------------------------------------------
;Based on Winamp_Lock_Pause by MrInferno
;Posted: Fri Apr 21, 2006 4:49 am
;Source: http://www.autohotkey.com/forum/topic9384.html
;---------------------------------------------------------------
;Winamp_Lock_Pause was/is based on script codes from "shimanov"
;Posted: Thu Sep 15, 2005 12:26 am
;Source: http://www.autohotkey.com/forum/viewtopic.php?t=5359
;Posted: Tue Dec 06, 2005 9:14 pm
;Source: http://www.autohotkey.com/forum/viewtopic.php?t=6755
;---------------------------------------------------------------
;Initialize global constants
WTS_SESSION_LOCK := 0x7
WTS_SESSION_UNLOCK := 0x8
NOTIFY_FOR_ALL_SESSIONS := 1
NOTIFY_FOR_THIS_SESSION := 0
WM_WTSSESSION_CHANGE := 0x02B1
notify_lock_unlock()
{
Global WM_WTSSESSION_CHANGE
Global NOTIFY_FOR_ALL_SESSION
hw_ahk := FindWindowEx( 0, 0, "AutoHotkey", a_ScriptFullPath " - AutoHotkey v" a_AhkVersion )
OnMessage( WM_WTSSESSION_CHANGE, "Handle_WTSSESSION_CHANGE" )
success := DllCall( "wtsapi32.dll\WTSRegisterSessionNotification", "uint", hw_ahk, "uint", NOTIFY_FOR_ALL_SESSIONS )
if( ErrorLevel OR ! success )
{
success := DllCall( "wtsapi32.dll\WTSUnRegisterSessionNotification", "uint", hw_ahk )
;If DLL registration fails, wait 20 seconds and try again
Sleep, 20000
notify_lock_unlock()
;MsgBox, [WTSRegisterSessionNotification] failed: EL = %ErrorLevel%
}
return
}
Handle_WTSSESSION_CHANGE( p_w, p_l, p_m, p_hw )
; p_w = wParam ;Session state change event
; p_l = lParam ;Session ID
; p_m = Msg ;WM_WTSSESSION_CHANGE
; p_hw = hWnd ;Handle to Window
{
Global WTS_SESSION_LOCK
Global WTS_SESSION_UNLOCK
If ( p_w = WTS_SESSION_LOCK )
{
on_lock()
}
Else If ( p_w = WTS_SESSION_UNLOCK )
{
on_unlock()
}
}
FindWindowEx( p_hw_parent, p_hw_child, p_class, p_title )
{
return, DllCall( "FindWindowEx", "uint", p_hw_parent, "uint", p_hw_child, "str", p_class, "str", p_title )
}
notify_lock_unlock()
; Calls function "on_lock()" when computer is locked and "on_unlock()" when computer is unlocked
on_lock()
{
Send, {Media_Play_Pause}
}
on_unlock()
{
Send, {Media_Play_Pause}
}
只要我在媒体播放器上播放内容,它就能正常工作。如果它暂停了,那么当我锁定 PC 时它就会开始播放。
我似乎找不到 Windows Media Player 暂停/播放的任何命令行选项。
有人知道如何让这个脚本正常工作吗?或者如果你有更好的想法,请告诉我。
答案1
对于 Chris F 来说 - 这是一个在您锁定 PC 时关闭显示器、暂停媒体播放器并将 IM 程序置于 AFK 状态的程序。