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

时间:2015-12-27 12:02:12

标签: visual-studio autohotkey

我已经重新设计了几把键,这些键一直很好用;但是,我正在努力摆脱视觉工作室中的弹出对话:

enter image description here

以下是我的尝试:

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

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

2 个答案:

答案 0 :(得分:1)

  

我做错了什么?

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

  • ALT + A -Hotkey的重点是什么?如果窗口弹出,为什么不按 Enter ??

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

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

  • return

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

btw酷名兄弟

答案 1 :(得分:1)

确保使用autohotkey安装文件夹中的window spy实用程序获取窗口标题和文本 有几种方法可以关闭一个窗口,有时你需要更强大一些。您甚至可能需要使用管理员权限运行脚本。您也不需要定义必须按下的热键来摆脱窗口。您可以完全自动化整个过程。试一试:

#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%
}