Jump to content

AutoIt to move the mouse and click close button on a program


zargon33
 Share

Recommended Posts

Hello all, I am just learning how to use AutoIt, and how to use it to move my mouse pointer and close out a window. I am able to get the mouse to move to a specific point on the screen, and execute a mouse click, but this is only if the program window is in that particular spot every time. It does work, I just need to make sure the window is in that spot. However, the program window isn't always in the same place when it opens after closing.

I've got this going so far:

Opt("MouseCoordMode",0)
MouseMove(1180, 180, 1)
MouseClick("left")

I changed the MouseCoordMode to 0, thinking this would do something relative to the open window but it doesn't appear to make any difference if the program window is active or not.

This works fine if I set the program to that particular point on the screen every time, which I can get by with, but I figured I'd post my problem here to see if someone can point me in the right direction to learn how to always find the top right X (exit button) of the program window, regardless of where the window might be on screen.

Link to comment
Share on other sites

  • Moderators

zargon33,

If you want to find the current position of a window, then use WinGetPos - details are in the Help file. But if all you want to do is close the window, you might find WinClose a simpler solution. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

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

 

Link to comment
Share on other sites

zargon33,

If you want to find the current position of a window, then use WinGetPos - details are in the Help file. But if all you want to do is close the window, you might find WinClose a simpler solution. :evil:

M23

Thank you Melba23, that did it. Wow, I can't believe how easy it is to use AutoIt so far! Luckily my needs are not so advanced. ;)

I just used:

WinClose("Program Name")

Jeez. Simple.

Link to comment
Share on other sites

Hello all, I am just learning how to use AutoIt, and how to use it to move my mouse pointer and close out a window. I am able to get the mouse to move to a specific point on the screen, and execute a mouse click, but this is only if the program window is in that particular spot every time. It does work, I just need to make sure the window is in that spot. However, the program window isn't always in the same place when it opens after closing.

I've got this going so far:

Opt("MouseCoordMode",0)
MouseMove(1180, 180, 1)
MouseClick("left")

I changed the MouseCoordMode to 0, thinking this would do something relative to the open window but it doesn't appear to make any difference if the program window is active or not.

This works fine if I set the program to that particular point on the screen every time, which I can get by with, but I figured I'd post my problem here to see if someone can point me in the right direction to learn how to always find the top right X (exit button) of the program window, regardless of where the window might be on screen.

Okey i'm not sure whether this will help u out 100% but i guess this script will do the job for most of the windows,i'm still working to find out how to click close on those windows which comes randomly and don't want to maximize.

anyways hope the script will help.i have just modified a script from the help file.it should allow you to pull up any notepad window even if it is not active,maximize it,and close it by clicking on the predefined co-ords or sending Alt-F4 ;)

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.0.0
 Author:         IDK(sandeep_laik@mindtree.com)

 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here

HotKeySet("{F9}", "Fastrack")
HotKeySet("{ESC}", "Terminate")
HotKeySet("+!d", "ShowMessage")  ;Shift-Alt-d

;;;; Body of program would go here ;;;;
TrayTip("Info","F9 to close any Notepad window,ESC to terminate.",30,1)

While 1
    Sleep(100)
WEnd
;;;;;;;;

Func Fastrack()
    TrayTip("Working","Looking for any Notepad",30,0)
    WinActivate("[Class:Notepad]","") ;<-----------enter the name of your program if u know it :)
    $title=WinGetTitle("[ACTIVE]")
    WinGetHandle($title,"")
    WinSetState($title,"",@SW_MAXIMIZE)
    MouseClick("left",1250,40) ;<-----------------give the co-ord of u'r program's close button when it's maximized
    ;send("!{F4}") <-------- You can use this too
EndFunc

Func Terminate()
    TrayTip("Terminating","IDK[sandeep_laik@mindtree.com]",30,0)
    sleep(3000)
    Exit 0
EndFunc

Func ShowMessage()
    TrayTip("Info","F9 to close any Notepad window,ESC to terminate.",30,1)
EndFunc

good luck...

addins.au3

Link to comment
Share on other sites

  • Moderators

zargon33,

As a beginner, you will find that reading the Help file (at least the first few sections - Using AutoIt, Tutorials and the first couple of References) will help you enormously. You should also look at the excellent tutorials that you will find here and here. There are even video tutorials on YouTube if you prefer watching to reading. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

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

 

Link to comment
Share on other sites

Well, the WinClose did indeed close the program window, but I realized there is a slight problem - when the program is running a particular loaded file, the window reads "Filename - Program Name". The filename is going to be different most of the time. I've been trying to use the [Class:Name] feature but not getting it to work correctly. I will look at the code you just posted, thanks.

Link to comment
Share on other sites

  • Moderators

zargon33,

To match the title in that case, you need to use AutoItSetOption with the ("WinTitleMatchMode", 2) option. ;)

Again the Help file is your friend for more details.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

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

 

Link to comment
Share on other sites

Well, the WinClose did indeed close the program window, but I realized there is a slight problem - when the program is running a particular loaded file, the window reads "Filename - Program Name". The filename is going to be different most of the time. I've been trying to use the [Class:Name] feature but not getting it to work correctly. I will look at the code you just posted, thanks.

Hope this example will help to understand better.

Example :

If "a.txt - Notepad" is your complete title, where it can be any file but the "- Notepad" substring remains same.

Opt("WinTitleMatchMode", 2)
;---other codes
WinActivate("- Notepad", "")

And it will activate any window with that substring " - Notepad" in the title. ;)

good luck..

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...