【问题标题】:using ahk to close a pop up dialogue within visual studio使用 ahk 关闭 Visual Studio 中的弹出对话框
【发布时间】:2016-04-01 12:23:22
【问题描述】:

我重新映射了几个键,效果很好;但是,我很难摆脱 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

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

【问题讨论】:

  • 你想完成什么?为什么不能直接点击确定并解决问题?

标签: visual-studio autohotkey


【解决方案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

顺便说一句很酷的名字兄弟

【讨论】:

  • 谢谢!这是我到目前为止所得到的,pastebin.com/9pASqZEh,我已经将它包装在 A 循环中,但它似乎根本没有响应。你都有些什么想法呢?我非常感谢您的帮助!度过愉快的一周
  • 你不需要if winactive()紧跟在winwaitactive之后,因为后者暗示了前者
  • @PleaseStopUpvotingMe 我仍然不明白Send !{F4}n 的含义,但是 - 代码对我来说看起来不错,不知道什么不起作用。干杯
  • 您应该将msgboxes 放在您的代码中,并找出发生了什么以及什么不起作用。
【解决方案2】:

确保使用自动热键安装文件夹中的 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%
}

【讨论】:

    猜你喜欢
    • 2020-04-02
    • 1970-01-01
    • 2019-02-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-22
    相关资源
    最近更新 更多