Jump to content
Sign in to follow this  

How to properly focus windows

Recommended Posts


Hey guys, I have another newb question. So far, the only way I know of focusing a window is by using it's title. So if I have a window named "ABCD" and then I want to focus a window called "AD" I have a problem, because substring "AD" is contained within "ABCD".

To fix this I tried using the command:

Opt("WinTitleMatchMode", 3)

API for this command can be seen here: http://www.autoitscript.com/autoit3/docs/functions/AutoItSetOption.htm However, I still get the same problem. If I focus "ABCD" first, I can't focus "AD" after. Here is my script so far:

;Alters the method used to search window titles. For more info see also:
Opt("WinTitleMatchMode", 3)

; Prompt the user to run the script - use a Yes/No prompt (4 - see help file)
Local $answer = MsgBox(4, "Looper tester", "This script will run an infinite loop for a test.  Run?")

; Check the user's answer to the prompt (see the help file for MsgBox return values)
; If "No" was clicked (7) then exit the script
If $answer = 7 Then
    MsgBox(0, "AutoIt", "OK.  Bye!")

Local $launcherName = "ABCD"
Local $appExeName = "AD"

; Run Launcher

; Wait for the launcher to become active
MouseMove ( 900, 600)
MouseClick ( "left")

MouseMove ( 900, 600)
MouseClick ( "left")

;Loop stuff
; Finished!

What am I doing wrong? Why can't I focus $exeExeName? Thanks in advance!

I hope it is clear that this question is about substrings and window focus. This is within the user agreement and forum rules.

Share this post

Link to post
Share on other sites

This here --> and this topic attempting to avoid a locked topic is a good way to get banned!

My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry.  

Share this post

Link to post
Share on other sites


When you argued about the locking of your other thread, I specifically told you:

"I strongly suggest that you do not begin any further threads about automating any game or its servers - or indeed any other subject which is prohibited by the Forum rules"

Those Forum rules state quite clearly:

"Do not create a new topic on a subject if a previous topic on that subject was locked"

As you seem not to have read the rules very carefully, I am giving you a few days posting holiday to properly examine them so that you will not infringe them in future. And a word to the wise - do not argue about it as you have already tried my patience enough today. ;)


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:


ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area


Share this post

Link to post
Share on other sites
This topic is now closed to further replies.
Sign in to follow this  

  • Similar Content

    • therks
      By therks
      Has anybody else noticed that Windows 7 reacts ignorantly when you use the Windows key + arrow key shortcuts on a GUI with GUIEventMode set to 1? I discovered this recently when I was working on an app where I wanted complete control over the maximize/minimize buttons.
      Just give it a spin:
      #include <GUIConstants.au3> Opt('GUIEventOptions', 1) $hGUI = GUICreate('', 300, 200, Default, Default, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX)) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_MAXIMIZE ToolTip('Maximized') Case $GUI_EVENT_MINIMIZE ToolTip('Minimized') Case $GUI_EVENT_RESTORE ToolTip('Restored') Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Run that, then hit Win+Up or Win+Down. None of those events get triggered, and it still maximizes/minimizes. Although I can't get it to restore down from a maximize unless the window is also resizable ($WS_THICKFRAME in the style).
      Is there a way to stop Windows from doing what it wants or is the only option to check with WinGetState() and then change it back?
      Windows 10 seems to respect my settings, and I don't have any other versions to test on.

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.