私は、1 つのホットキーで電卓を起動するか、すでに開いている場合はウィンドウを「アクティブ化」するか、すでにアクティブ化されている場合は電卓を閉じるように、次のスクリプトを作成しました。電卓が最小化されている場合は復元できないことを除けば、すべて正常に動作します。私の知る限り、すべて正しく実行しています。何が問題なのかわかりません。AHK のドキュメントには、最小化されたウィンドウで WinActivate を呼び出すと、まずそのウィンドウが復元されると記載されていますが、これは嘘です。MsgBox 行のコメントを解除すると、ウィンドウが最小化されているときにメッセージは表示されますが、それ以上何もできません。
If WinExist("Calculator") {
;MsgBox Calculator Exists.
IfWinActive
WinKill
Else
WinGet, winState, MinMax
If (winState = -1)
WinRestore, Calculator
WinActivate, Calculator
}
Else {
run calc
WinActivate, Calculator
}
答え1
どの OS を使用していますか? タイトルに ahk_class を追加すると、コードは Win10 でも動作します。
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
}
答え2
これが私のために働くものなのです。
;------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
私がよく使うもの:
;------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
しかし、この解決策では、ホットキーを 2 回押す必要があることがよくあります。1 回目はアクティブにするため (一番上になくても、まだ見える状態)、2 回目は最小化するためです。これが誰かの役に立つことを願っています。