Sign in to follow this  
Followers 0
Athos

WinActivate Help

5 posts in this topic

Hi Guys. You've all been extremely helpful to me so far.

Anyways, I was wondering if there was a way to get winActivate working without using the actual title of the application.

The problem for me is that the application I'm trying to script has a title that is constantly changing to indicate which version of a project the user is using. This means, I can't rely on the title to activate the window.

I tried using a control ID of the window, but that didn't seem to work...

Share this post


Link to post
Share on other sites



Look in the help file for WinActivate and what you can use in place of the actual window title.

See here for the online version.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Thanks for the Link BrewMan :D

I got it working as follows

AutoItSetOption("WinTitleMatchMode", 2)

winActivate("Thepartofthetitlethatdoesntchange")

Edited by Athos

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I actually have a couple related questions on this topic... when using Opt() can you use more than one at the same time? I understand that the WinTextMatchMode's default is 1 but I'm just using it as an example.

Opt("WinTitleMatchMode", 2)

Opt("WinTextMatchMode", 1)

WinWait ("InstallShield Wizard", "Select the language")

WinActivate ("InstallShield Wizard", "Select the language")

WinWaitActive("InstallShield Wizard", "Select the language")

ControlClick("InstallShield Wizard", "Select the language", 1)

And when using Opt() do you have to state it before each bundle of commands for each dialog box or do you just have to state it at the begining of the script and it carries forward? Does it stay that way until I change it?

Thanks!

Edited by Esquared

Share this post


Link to post
Share on other sites

You can use multiple options in the same script, and they stay until you change them to something else.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Similar Content

    • anthonyjr2
      By anthonyjr2
      I have come across a weird issue that I am not sure how to solve. For some reason, whenever I call WinActivate in certain scenarios instead of opening the single window that already exists, it will create a new blank tab. It should be able to be recreated with this:
      AutoItSetOption("WinTitleMatchMode", 2) Sleep(1000) For $i=0 To 10 WinActivate("Internet Explorer") Next I am not actually doing this in my code, it is just to demonstrate the fact that new tabs keep popping up. Does anyone know why this happens?
       
      EDIT: So I am not sure how reproducible this is, because it only happens every once in a while for me. I will update with more info if I find out anything.
    • AndyS01
      By AndyS01
      I have a script that opens an editor (Notepad) and inserts text into its window, but the text insertion fails.  The WinActivate() does not always give focus to the newly loaded Notepad and the WinMenuSelectItem() fails.
      Here is my test file:
       
      #NoTrayIcon #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=THTracker.ico #AutoIt3Wrapper_UseUpx=n #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 #AutoIt3Wrapper_UseX64=N #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** Opt('MustDeclareVars', 1) Opt("WinTitleMatchMode", -2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase _Main() Func _Main() add2editor("Line1" & @CRLF & "Line2" & @CRLF & "Line3" & @CRLF) EndFunc ;==>_Main Func add2editor($sOutput) Local $cmd, $hWnd, $ret, $title, $loopcnt, $maxcnt = 10 $cmd = "C:\windows\system32\notepad.exe" ConsoleWrite("Start the editor" & @CRLF) Run($cmd) $title = "Notepad" ConsoleWrite("Wait til the editor gui exists" & @CRLF) $loopcnt = 0 While (1) $ret = WinWait($title, "", 3) ConsoleWrite("+++:" & @ScriptLineNumber & ":[" & $loopcnt & "] $ret = " & $ret & @CRLF) $hWnd = $ret If ($ret <> 0) Then ExitLoop $loopcnt += 1 If ($loopcnt > $maxcnt) Then Exit Sleep(125) WEnd MsgBox(0, "A-" & @ScriptLineNumber, Hex($hWnd)) ConsoleWrite("Give focus to the editor" & @CRLF) $loopcnt = 0 While (1) $ret = WinActivate($hWnd) ConsoleWrite("+++:" & @ScriptLineNumber & ":[" & $loopcnt & "] @error = " & @error & ", $ret = " & $ret & @CRLF) $hWnd = $ret If ($ret <> 0) Then ExitLoop $loopcnt += 1 If ($loopcnt > $maxcnt) Then Exit Sleep(125) WEnd MsgBox(0, "B-" & @ScriptLineNumber, Hex($hWnd)) ConsoleWrite("Do a File -> New" & @CRLF) $loopcnt = 0 While (1) ; $ret = WinMenuSelectItem($hWnd, "", "&File", "New") ConsoleWrite("+++:" & @ScriptLineNumber & ":[" & $loopcnt & "] @error = " & @error & ", $ret = " & $ret & @CRLF) If ($ret = 1) Then ExitLoop $loopcnt += 1 If ($loopcnt > $maxcnt) Then Exit Sleep(125) WEnd MsgBox(0, "C-" & @ScriptLineNumber, Hex($hWnd)) ;Local $str = ClipGet() ; save whatever is in the clipboard Send("^a") ; select all existing text in the editor's window ConsoleWrite("put the new text into the clipboard" & @CRLF) ClipPut($sOutput) Send("^v") ; paste it into the editor's window ;;;ClipPut($str) ; restore the previous contents of the clipboard EndFunc ;==>add2editor  
    • Rhazz
      By Rhazz
      Hi, I'm trying to upload a file with a web browser but I can't select the Open File window to select the file that I want to upload.
      TL;DR I can't handle the Open File window of Chrome and MS Edge. AutoIt just doesn't find it by its title (in Firefox yes, but not on Chrome and MS Edge).
      With another software (Selenium Webdriver in Python) I access to a web page with a common HTML5 file uploader and I click on it, but when the Open File window comes up, I want to select a file and press Enter (write the filepath that I give and press Enter key or Open button).
      I have the idea, and I have the script on AutoIt too... but it doesn't work on Windows Edge and Chrome, only works on Firefox and Pale Moon (who are basically the same).
      Here is my code:
      #include <MsgBoxConstants.au3> $title = "Abrir" ; My Windows is in spanish, but I guess it's "Open" in English and it's the same code WinActivate($title) If WinActive($title) Then send("C:\Users\myuser\images\my_image.jpg") Send("{ENTER}") Else MsgBox($MB_SYSTEMMODAL, "WinActive", "Window not found.") EndIf In Firefox (and Pale Moon) the Open File window comes up, the file path is written and the Enter key is pressed. It works perfect.
      In Chrome and Edge, I never see the Open File window on top... and I neither see "Window not found" message (seems like AutoIt finds it but doesn't send keys).
      Edit: before to send this post, I started thinking again and... after several tests, I discovered one thing: when you select the window, in Firefox (and Pale Moon) the cursor goes to the combobox (where I have to put the text) and it's possible to write just after clicking (or opening, what in AutoIt it is "Activate" I guess) the window but in Chrome and Edge it isn't like that, when you click the window, the cursor doesn't go to the combobox.
      With that "discovery", I tried to select the combobox but... I failed again. And now I have no idea how to go ahead.
      #include <MsgBoxConstants.au3> $title = "Abrir" WinActivate($title) If WinActive($title) Then ControlClick($title, "", 1148) ; Still it does not work send("C:\Users\myuser\images\my_image.jpg") Send("{ENTER}") Else MsgBox($MB_SYSTEMMODAL, "WinActive", "Window not found.") EndIf  
    • TheFixer
      By TheFixer
      Basically i am trying to make a script that detects if the currently active window is 1920 x 1080 or bigger. If it detects a window that is active, that is indeed that size. It will do some stuff. 
      The problem i am having is that it is detecting my desktop whenever i click on my desktop, so it's doing stuff when i don't want it to.

      So all i need to know, is how can i do a simple check to see if a window = a title.

      Here is what i have so far
      $wintitledesktop = WinGetTitle("[ACTIVE]") If not $wintitledesktop = "Program Manager" Then ;does stuff endif Program Manager is what my desktop is called btw. 

      The problem with that code is that the script is still detecting the desktop and doing the code.
       
      In case you need the whole section of the code, here it is.

       
      $winsizecheck1 = WinGetClientSize("[ACTIVE]") $wintitledesktop = WinGetTitle("[ACTIVE]") If WinActive("[ACTIVE]") Then sleep(100) If $winsizecheck1[0] >= 1920 Then If $winsizecheck1[1] >= 1080 Then If not $wintitledesktop = "Program Manager" Then $gamesfolderstate = WinGetState($gamesfolder) If WinExists($gamesfolder) Then If Not BitAND($gamesfolderstate, 16) Then WinSetState($gamesfolder,"",@SW_MINIMIZE) EndIf EndIf EndIf EndIf EndIf EndIf  
    • afallenhope
      By afallenhope
      Hello all I am trying to use this function to detect if a specific window is running. Then for it to activate it and send an ALT+F command to close the window. But I cannot seem to get it to detect the window and subsequently the rest of the code does not work. 
      #include <MsgBoxConstants.au3> Handleit() Func Handleit() If WinExists("[CLASS:MsiDialogCloseClass]","InstallShield") Then WinActivate("[CLASS:MsiDialogCloseClass]","Installshield") Send("!f") Else MsgBox($MB_SYSTEMMODAL, "", "Uhhh... something didn't work. Fix it!") EndIf EndFunc Is there anything that I can substitute for the CLASS? 
      Thank you for taking the time to read my question! 
      -Richard