使用ahk关闭Visual Studio中的弹出对话框 [英] using ahk to close a pop up dialogue within visual studio

查看:241
本文介绍了使用ahk关闭Visual Studio中的弹出对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我重新映射了一些键,这些键工作得很好;但是,我很难摆脱Visual Studio中的弹出对话框:

I've remapped a few keys, which has been working fine; however, I'm having a difficult time trying to get rid of a pop up dialogue within 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

但是,我什么也没收到.

However, I get no response whatsoever.

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

The entire script including a few key remappings is below:

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

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

推荐答案

请确保使用autopykey安装文件夹中的window spy实用工具获取窗口标题和文本.
有几种关闭窗口的方法,有时您必须更加用力.甚至有可能需要使用管理员权限运行脚本.您也不需要定义必须退出窗口的热键.您可以完全自动化整个过程.试试看:

Make sure to get the window title and text using the window spy utility from your autohotkey install folder.
There are several ways to close a window, sometimes you have to be a bit more forcefully. It's even possible that you need to run your script with admin privileges. You also don't need to define a hotkey which has to be pressed to get rid of the window. You can completely automate the whole process. Give this a try:

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

这篇关于使用ahk关闭Visual Studio中的弹出对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆