Jump to content

GUI Button - script won't run


jgq85
 Share

Recommended Posts

Ok I'm new and went through stick/pinned thread and read through FAQ on Koda documentation, but still think I need assistance from someone who has time to lend a hand.

This is my simple 1 button GUI I created (to test):

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=Form1.kxf
$Form1 = GUICreate("1button Closer", 196, 82, 192, 122)
$Button1 = GUICtrlCreateButton("Close Incident", 8, 16, 91, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
  Case $GUI_EVENT_CLOSE
   Exit
EndSwitch
WEnd

How do I make the button, when pushed, to run this script?

;select the Edit Incident Window
HotKeySet("{F4}", "ExitProg")
Func ExitProg()
    Exit 0 ;;Exits the program
EndFunc
WinActivate("OnTime)", "")
$coord = PixelSearch( 380, 187, 1745, 401, 0xFF0000 )
If Not @error Then
; Click the Critical Incident
MouseClick("left", $coord[0], $coord[1], 1)
Sleep(1000)
Else
          MsgBox(4096,"", "Critical Incident Not Found")
EndIf

I tried using putting the script I want to run in between Func Button1() and EndFunc and but button still didn't execute the script.

The script only runs if I run it independently from the GUI script.

This is the first GUI/script I've tried to create together...

Link to comment
Share on other sites

Not really enough code for me to test, but I think it should look a little more like this:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
 
HotKeySet("{F4}", "ExitProg")
$Form1 = GUICreate("1button Closer", 196, 82, 192, 122)
$Button1 = GUICtrlCreateButton("Close Incident", 8, 16, 91, 25)
GUISetState(@SW_SHOW)
 
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            _Button1()
    EndSwitch
WEnd
 
Func _Button1()
    WinActivate("OnTime)", "")
    $coord = PixelSearch(380, 187, 1745, 401, 0xFF0000)
    If Not @error Then
        ; Click the Critical Incident
        MouseClick("left", $coord[0], $coord[1], 1)
        Sleep(1000)
    Else
        MsgBox(4096, "", "Critical Incident Not Found")
    EndIf
EndFunc
 
Func ExitProg()
    Exit ;Exits the program
EndFunc   ;==>ExitProg
Edited by sleepydvdr

#include <ByteMe.au3>

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