您需要一个timer 来使用WinGet 命令获取所有窗口的列表,以便检测新窗口:
#NoEnv
#SingleInstance Force
#Persistent
WinList()
SetTimer, FullScreen, 300
Return
FullScreen:
active_id := ""
WinGet, active_id, ID, A
If !InStr(wins, active_id)
{
SetTimer, FullScreen, off
WinGetClass, ActiveClass, ahk_id %active_id%
If (ActiveClass="ApplicationFrameWindow")
SendInput, +#{Enter}
else
SendInput, {F11}
WinList()
WinWaitNotActive, ahk_id %active_id%
SetTimer, FullScreen, on
}
Return
WinList(){
global
list := ""
wins := ""
WinGet, id, list,,, Program Manager
Loop, %id%
{
this_ID := id%A_Index%
WinGetTitle, title, ahk_id %this_ID%
If (title = "")
continue
WinGetClass, class, ahk_id %this_ID%
If (class = "")
continue
WinGet, Style, Style, ahk_id %this_ID%
if !(Style & 0x10000000) ; WS_VISIBLE
{
WinGet, ExStyle, ExStyle, ahk_id %this_ID%
If (this_ID != "0x00000180")
continue
}
wins .= this_ID ? this_ID "`n" : ""
wins := Trim(wins)
}
}
编辑:
Shell Hook 为您提供更好的服务:
#NoEnv
#SingleInstance Force
Gui +LastFound
hWnd := WinExist()
DllCall("RegisterShellHookWindow", UInt,WinExist())
MsgNum := DllCall( "RegisterWindowMessage", Str,"SHELLHOOK" )
OnMessage( MsgNum, "ShellMessage" )
return
ShellMessage( wParam,lParam )
{
WinGet, pname, ProcessName, ahk_id %lParam%
WinGetTitle, title_W, ahk_id %lParam%
WinGetClass, class_W, ahk_id %lParam%
If ((title_W != "") && (class_W != ""))
{
If ( wParam = 1 ) ; 1 means HSHELL_WINDOWCREATED
{
If (class_W != "Windows.UI.Core.CoreWindow")
SendInput, {F11}
}
else
If ( wParam = 2 ) ; 2 means HSHELL_WINDOWDESTROYED
{
If (class_W = "Windows.UI.Core.CoreWindow")
{
If WinActive(title_W "ahk_class ApplicationFrameWindow")
SendInput, +#{Enter}
}
}
}
}