使用 ahk 关闭 visual studio 内的弹出对话框

using ahk to close a pop up dialogue within visual studio

我已经重新映射了几个键,一直工作正常;但是,我很难摆脱 visual studio:

中的弹出对话框

这是我尝试过的方法:

WinWaitActive, Microsoft Visual Studio
If WinActive("Microsoft Visual Studio")
{
  WinGetText, HayStack
  Needle = "A network-related or instance-specific error"
  IfInString, Haystack, %Needle%
  {
      MsgBox, The string was found.
      return
  }
  else
      Sleep, 1
}
return

然而,我没有得到任何回应。

包括一些关键重新映射在内的整个脚本如下:

SetTitleMatchMode 2
!z::Send, !{F4}
!x::Send, !fc
!c::Send, 23481241240910324
^d::Send {End}{Shift Down}{Up}{End}{Shift Up}{Backspace}
!a::
If WinActive("Microsoft Visual Studio")
{

}
else
{
  Send !{F4}n
}
return
WinWaitActive, Microsoft Visual Studio
If WinActive("Microsoft Visual Studio")
{
  WinGetText, HayStack
  Needle = "A network-related or instance-specific error"
  IfInString, Haystack, %Needle%
  {
      MsgBox, The string was found.
      return
  }
  else
      Sleep, 1
}
return

我做错了什么?我如何摆脱这个对话?

What am I doing wrong?

  • Needle = "A network-related or instance-specific error" - 字符串赋值不像 AHK 那样工作。您可以使用 Needle := "A network..."Needle = A network....

  • 你的ALT+A-热键有什么用?如果 window 弹出,你为什么不直接按 Enter??

  • If WinActive("Microsoft Visual Studio")
     {
    
     }
     else
     {
       Send !{F4}n
     }
    

    那么,当弹出 活动时关闭 window??

  • return

    此关键字后的所有内容都不会被执行。您的脚本 永远不会 到达 WinWaitActive, Microsoft Visual Studio.

顺便说一句好名字兄弟

确保使用 window 间谍实用程序从您的自动热键安装文件夹中获取 window 标题和文本。
关闭一个window有几种方法,有时候你得用力一点。您甚至可能需要 运行 您的脚本具有管理员权限。您也不需要定义必须按下才能摆脱 window 的热键。您可以完全自动化整个过程。试一试:

#Persistent ;Ensure the script doesn't exit immediately
If not A_IsAdmin ;force the script to run as admin
{
    Run *RunAs "%A_ScriptFullPath%"
    ExitApp
}

;Enter the correct win title and a correct substring of the win text and maybe also the ClassNN of the button whoch closes it
windowTitle = Microsoft Visual Studio
windowText = A network-related or instance-specific error
closeButton = Button1

;Call CloseWindow periodically passing the contents of above variables as arguments:
CloseWindowWithBoundArgument := Func("CloseWindow").bind(windowTitle, windowText, closeButton)
SetTimer, %CloseWindowWithBoundArgument%

;Wait for a window to exist, then close it:
CloseWindow(winTitle,winText,buttonClassNN) {
    WinWait, %winTitle%, %winText% ;wait until the window exists
    ;There are multiple methods to close a window:

    ;Close window method 1 (similar to pressing alt+F4)
    PostMessage, 0x112, 0xF060,,, %winTitle%, %winText%

    ;Close window method 2 (sends a WM_CLOSE message; somewhat forcefully)
    WinClose, %winTitle%, %winText%

    ;Close window method 3 (forcefully closing a window using server different methods internally)
    WinKill, %winTitle%, %winText%

    ;Close window method 4 (clicking a button to close the window)
    ControlClick, %buttonClassNN%, %winTitle%, %winText%
}