Ich habe das folgende Skript erstellt, um einen Hotkey zu haben, der den Rechner startet oder, wenn er bereits geöffnet ist, das Fenster „aktiviert“ oder, wenn er bereits aktiviert ist, den Rechner schließt. Es funktioniert alles einwandfrei, außer dass es nicht funktioniert, den Rechner wiederherzustellen, wenn er minimiert ist. Soweit ich das beurteilen kann, habe ich alles richtig gemacht. Ich verstehe nicht, wo das Problem liegt. Die AHK-Dokumentation behauptet, dass, wenn Sie WinActivate in einem minimierten Fenster aufrufen, dieses Fenster zuerst wiederhergestellt wird, aber das ist eine Lüge. Wenn ich die MsgBox-Zeile auskommentiere, erhalte ich immer noch eine Meldung, wenn das Fenster minimiert wird, aber es kann nichts weiter tun.
If WinExist("Calculator") {
;MsgBox Calculator Exists.
IfWinActive
WinKill
Else
WinGet, winState, MinMax
If (winState = -1)
WinRestore, Calculator
WinActivate, Calculator
}
Else {
run calc
WinActivate, Calculator
}
Antwort1
Welches Betriebssystem verwendest du? Dein Code funktioniert bei mir unter Win10, wenn ich dem Titel die ahk_class hinzufüge:
If WinExist("Calculator ahk_class ApplicationFrameWindow")
{
;MsgBox Calculator Exists.
IfWinActive
WinClose
Else
{
WinGet, winState, MinMax
If (winState = -1)
{
WinRestore
WinActivate
}
}
}
Else
{
run calc
WinWait, Calculator
WinActivate
}
Antwort2
Das ist es, was für mich funktioniert.
;------hotkey to open/close explorer------
^LWin:: ;control and leftwindows
if WinExist("ahk_class ActualTools_TabbedExplorerContainerWindow"){ ; if the window exists
if WinActive("ahk_class ActualTools_TabbedExplorerContainerWindow") or WinActive("ahk_exe Explorer.EXE")
WinMinimize, ahk_class ActualTools_TabbedExplorerContainerWindow
else{
WinActivate ; otherwise make it the active window
}
}else
run, explorer.exe ;otherwise not open, open explorer
return
Ich verwende:
;------hotkey to open/close explorer------
^LWin:: ;control and leftwindows
;WinGetClass, Clipboard, A ;Use this to get the name(class?) of the window you want the script to open. https://stackoverflow.com/questions/45642727/what-is-ahk-class-how-can-i-use-it-for-window-matching
if WinExist("ahk_class ActualTools_TabbedExplorerContainerWindow"){ ; if the window exists
WinGet, state, MinMax ;get the state of the window. is it maximized or minimized. this could be part of the issue
If state >= 0 ; if its not minimized, minimize it
WinMinimize
else
WinActivate ; otherwise make it the active window
}else
Run, Explorer.exe ;otherwise not open, open explorer
return
Bei dieser Lösung musste ich den Hotkey jedoch oft zweimal drücken. Einmal, um ihn zu aktivieren (wenn er nicht ganz oben war, ist er auch noch sichtbar) und dann noch einmal, um ihn zu minimieren. Hoffe, das hilft jemandem.