Jump to content

automatically click on a button without x y coordinates


LudwigIt
 Share

Recommended Posts

Good mornig, afternoon or evening,

I need your help!

I Keep it simple, if you dont click the button in 5 sec, the Programm click automatically without x y coordinates on the Button.

my code...

 

#include <GUIConstants.au3>
#include <WinAPISys.au3>
$Form1 = GUICreate("Form1", 625, 443, 190, 125)
$Button1 = GUICtrlCreateButton("Button1", 88, 72, 75, 25, 0)
GUISetState(@SW_SHOW)

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
 
 
case $Button1
Run("notepad.exe")
EndSwitch
WEnd

 

 

 

Link to comment
Share on other sites

  • Moderators

LudwigIt,

Welcome to the AutoIt forums.

A simple way to do what you want is to use a dummy control:

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

$hGUI = GUICreate("Test", 500, 500)
$cButton = GUICtrlCreateButton("Button", 10, 10, 80, 30)
$cDummy = GUICtrlCreateDummy()
GUISetState(@SW_SHOW)

; Set a timestamp
$iTimer = TimerInit()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cButton, $cDummy ; Both events fire this code
            MsgBox($MB_SYSTEMMODAL, "Hi", "Button pressed")
    EndSwitch

    ; Check timestamp valid and if delay over 5 secs
    If $iTimer <> -1 And TimerDiff($iTimer) > 5000 Then
        ; Fire dummy event
        GUICtrlSendToDummy($cDummy)
        ; Invalidate timestamp - try commenting this line and see what happens!!!!!!
        $iTimer = -1
    EndIf

WEnd

If you want to get a bit more complex you can differentiate between the button and the timer:

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

$hGUI = GUICreate("Test", 500, 500)
$cButton = GUICtrlCreateButton("Button", 10, 10, 80, 30)
$cDummy = GUICtrlCreateDummy()
GUISetState(@SW_SHOW)

; Set a timestamp
$iTimer = TimerInit()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cButton, $cDummy ; Both events fire this code
            ; But message changes depending on the event detected
            If GUICtrlRead($cDummy) = 9999 Then
                $sMsg = "Timer fired"
                ; Clear the dummy data - try commenting this line and see what happens!!!!!!
                GUICtrlSetData($cDummy, 0)
            Else
                $sMsg = "Button pressed"
            EndIf
            MsgBox($MB_SYSTEMMODAL, "Hi", $sMsg)
    EndSwitch

    ; Check timestamp valid and if delay over 5 secs
    If $iTimer <> -1 And TimerDiff($iTimer) > 5000 Then
        ; Fire dummy event
        GUICtrlSendToDummy($cDummy, 9999)
        ; Invalidate timestamp - try commenting this line and see what happens!!!!!!
        $iTimer = -1
    EndIf

WEnd

Please ask if you have any questions.

M23

P.S.

When you post code in future please use Code tags - see here how to do it.  Then you get a scrolling box and syntax colouring as you can see in my posts above. Thanks in advance for your cooperation.

 

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

  • 1 month later...

thank you Melba23, i am intersting to do something as LudwigIt says. but there is a one differencess. i need to run one exe file and click button inside of the exe when program is minimized. is there a way to help me related with this problems please? Thank you.

Link to comment
Share on other sites

  • Moderators

@atanik you already have a thread open on this subject. Please stick to one thread.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

  • Moderators

No need to remove it, simply use your own thread from this point forward...

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

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...