using ahk to close a pop up dialogue within visual studio

后端 未结 2 726
说谎
说谎 2021-01-25 19:16

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:

Here\

相关标签:
2条回答
  • 2021-01-25 19:48

    What am I doing wrong?

    • Needle = "A network-related or instance-specific error" - String assignments don't work like that in AHK. You either use Needle := "A network..." or Needle = A network....

    • What's the point of your ALT+A-Hotkey? If the window pops up, why don't you simply press Enter??

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

      So, close the window when the popup is not active??

    • return

      Everything after this keyword doesn't get executed. Your script will never reach WinWaitActive, Microsoft Visual Studio.

    btw cool name bro

    0 讨论(0)
  • 2021-01-25 20:00

    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%
    }
    
    0 讨论(0)
提交回复
热议问题