Jump to content

Buttons


Pandacyber
 Share

Recommended Posts

So i am having a problem making buttons run files when they are pressed. 

Below are the codes for the buttons. When i try to open my gui now it ONLY runs the mousemove file (which is my file for moving the mouse) and no longer opening the GUI. Please help.

 

; Create the GUI.
#include <GUIConstantsEx.au3>
#include "C:UserscollierDocumentsautoitmakemousemove.au3"
 
GuiCreate("HITS Palla", 400, 400)
 
 Local $button1 = GUICtrlCreateButton("Start", 120, 320, 85, 25)
    Local $button2 = GUICtrlCreateButton("Close", 210, 320, 85, 25)
 
    ; Display the GUI.
    GUISetState()
 
    Local $iPID = 0
 
    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $idClose
                ExitLoop
 
            Case $button1
                ; start button
                $button1 = Run("C:UserscollierDocumentsautoitmakemovemouse.au3")
 
            Case $button2
                ; cancel button
                Exitloop
 
 
        EndSwitch
    WEnd

 

 

Tell me what i am doing wrong.

Edited by Pandacyber
Link to comment
Share on other sites

  • Moderators

It's hard to tell from your script where the issue is (no error checking, and you're calling another script from within your script). Can you explain what application or window you're trying to manipulate? You may be able to control it without having to call your movemouse.au3 script.

"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

Your major problem is you're trying to Run an AutoIt script, they are not runnable because they're not executable. You need to use ShellExecute to run a script, but that only works if you have AutoIt installed on the computer you're trying to run the script on. Second problem is that your Run command was overwriting your $button1 variable, used to hold the control ID of the button, with the PID returned by the Run command, so the button would only work once.

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

Link to comment
Share on other sites

 

#include <ButtonConstants.au3>

#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
 
 
$Form1 = GUICreate("Form1", 196, 279, 373, 211)
$Button1 = GUICtrlCreateButton("Start", 16, 136, 161, 33)
$Button2 = GUICtrlCreateButton("Cancel", 16, 184, 161, 33)
GUISetState(@SW_SHOW)
 
 
 
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
 Case $GUI_EVENT_CLOSE
Case $nmsg = $Button1
ShellExecute("C:UserscollierDocumentsautoitmakemousemove.au3") 
Case $nmsg = $Button2
Exit
 
Exit
 
 
EndSwitch
wend

Alright this is what i got but it keeps saying that it cannot find my au3 file

Edited by Pandacyber
Link to comment
Share on other sites

Your major problem is you're trying to Run an AutoIt script, they are not runnable because they're not executable. You need to use ShellExecute to run a script, but that only works if you have AutoIt installed on the computer you're trying to run the script on.

 

.au3 is not runnable

Edited by Spider001
Link to comment
Share on other sites

I just noticed something else, you're using the Switch/Case statements incorrectly. You have it written in the syntax of a Select statement, a Switch works like this.

While 1

    $nMsg = GUIGetMsg()

    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1 ; <<<<<<<<<<<<<<<<<<
            ShellExecute("C:\Users\collier\Documents\autoitmake\mousemove.au3")
        Case $Button2 ; <<<<<<<<<<<<<<<<<<
            Exit
    EndSwitch

WEnd

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

Link to comment
Share on other sites

Glad to hear it, and sorry I didn't notice it sooner. :

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

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