Jump to content

GUI Auto keystroke


Guest Orlann
 Share

Recommended Posts

Guest Orlann

Hiya.. i have had AutoIt for.. 2-3 days now and i think i have made a chunk of progress... but... now i want to make a GUI version of said app.

The one i have now.. has the windowname, keystroke, delay.. all hard coded into the program. To make this useable for others.. i would like a prompt of some sort for them to put info in and be able to change it w/o having to reload. (reloading it can be done if its a MUST).

i'll attach the working (non gui) version.. then the non working GUI version.

any help here would be wonderfull.

autostroke.au3

MyGUI_v1.1b.au3

Link to comment
Share on other sites

all i have to say is rtfm...

[font="Times"] If anyone remembers me, I am back. Maybe to stay, maybe not.----------------------------------------------------------------------------------------------------------[/font][font="Times"]Things I am proud of: Pong! in AutoIt | SearchbarMy website: F.R.I.E.S.A little website that is trying to get started: http://thepiratelounge.net/ (not mine)[/font][font="Times"] ----------------------------------------------------------------------------------------------------------[/font][font="Arial"]The newbies need to stop stealing avatars!!! It is confusing!![/font]

Link to comment
Share on other sites

Guest Orlann

Hey it's better than what I was doing after 2-3 days...

<{POST_SNAPBACK}>

ty.. and.. i got it working.. sortof. It works when the program itself is the target application but not said other program (and i'm using the autoit window info app to conferm the name)... not sure why it works in one setting and not the other.. but here is my progress so far.

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Purpose: Allow user to enter in a window name, delay, and command
;   to send to said window every X delayed seconds. I have a working
;   NON Gui version of this application and it works. The benifit of
;   making it GUI is flexability. Version 1.0 is hardcoded with 
;   the delay, windowname, and command.
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;   
; Version Releases:
;    1.0 = all hard coded and zero flexability.
;    1.1 = Gui and not hardcoded. See bug list for further issues.
;
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Buglist:
;    Version 1.0 = no "bugs"
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;    Version 1.1 = Start/Stop doesn't work as intended. Once the values
;              are set the only way to change them is to close and reload
;              the program.
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;
; How it's "suposed" to work step by step w/ example
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;  1. User loads application
;  2. User enters info into 3 fields
;  3. User sets values and gets a visual conframation the values are saved.
;  4.a The program will not send commands to $name untill its is the activewindow
;  4.b User clicks on Start/Stop to activate program
;  5. User toggles to said program in $name
;  6. Application begins sending $command every $delay seconds untill 
;   PAUSE/Break (hotkey) or Start/Stop (app button) is pressed.
;  7. User changes values in windows. (step 1)
;  8. User saves values. (step 2)
;  9. BUG!!.. new command/timer not recognized.
;
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Includes
#include <GUIConstants.au3>
#include <string.au3>
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


;Create GUI
$WinMain = GUICreate("GUI AuToKeYStRoKe 2.0",370,400)
;$WinMain = GUICreate("GUI",370,400)
$name = ""
$command = ""
$delay = "5"
$x = 0
$Busy = 0
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

;Globals
Global $Paused , $running = 0
HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")
HotKeySet("{F8}", "Terminate")

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

;File Menu
$filemenu = GuiCtrlCreateMenu ("File")
$exititem = GuiCtrlCreateMenuitem ("Exit",$filemenu)
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

;Help Menu
$helpmenu = GuiCtrlCreateMenu ("Help")
$aboutitem = GuiCtrlCreateMenuitem ("About",$helpmenu)
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

;Buttons
$okbutton = GuiCtrlCreateButton ("Set Values",15,330,70,20)
$cancelbutton = GuiCtrlCreateButton ("Exit",87,330,70,20)
$run = GuiCtrlCreateButton ("Start",210,330,70,20)
$stop = GuiCtrlCreateButton ("Stop",280,330,70,20)
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

;Window info
$lbl_windowname = GuiCtrlCreateLabel("Window Name", 180, 10, 131, 21, 0x1000)
$tb_windowname = GuiCtrlCreateInput("", 10, 10, 131, 21)

;Delay Info
$lbl_delay = GuiCtrlCreateLabel("Delay (in milliseconds)", 180, 40, 131, 21, 0x1000)
$tb_delay = GuiCtrlCreateInput("", 10, 40, 131, 21)

;Command Info
$lbl_command = GuiCtrlCreateLabel("Command to send", 180, 70, 131, 21, 0x1000)
$tb_command = GuiCtrlCreateInput("", 10, 70, 131, 21)
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


;Conframation that values were set
$lbl_setWindowname = GuiCtrlCreateLabel(" -- Window Not set -- ", 10, 130, 131, 21, 0x1000)
$lbl_setDelay = GuiCtrlCreateLabel(" -- Delay Not set -- ", 10, 160, 131, 21, 0x1000)
$lbl_setCommand = GuiCtrlCreateLabel(" -- Command Not set -- ", 10, 190, 131, 21, 0x1000)
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


;Start GUI Loop Till exit
GuiSetState()
While 1
    $msg = GUIGetMsg()
    

    Select
        Case $msg = $GUI_EVENT_CLOSE Or $msg = $cancelbutton
            ExitLoop
        
    ;Case $msg = $fileitem
        ;$file = FileOpenDialog("Choose file...",@TempDir,"All (*.*)")
        ;If @error <> 1 Then GuiCtrlCreateMenuItem ($file,$recentfilesmenu)

        Case $msg = $exititem
            ExitLoop
        
        Case $msg = $run
        ;If $running = 0 Then
        ;   runProgram()
        ;Else
        ;   ExitLoop
        ;EndIf
        ;TogglePause()
            runProgram()
        
    ;Saves info and puts them in a lable for conframation
        Case $msg = $okbutton
            setName()
            setCommand()
            setDelay()

        Case $msg = $aboutitem
            Msgbox(0,"About","If you have this program... you know who made it.")
    EndSelect
WEnd

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

;Functions
Func SetVals()
    setName()
    setCommand()
    setDelay()
EndFunc

;Pause/break for alternative way to pause program
Func TogglePause()
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('GUI autofire is "Paused"',10,5)
    WEnd
    ToolTip("")
EndFunc

Func Terminate()
    Exit 0
EndFunc

Func setName()
    $name = GUICtrlRead($tb_windowname)
    GuiCtrlSetData($lbl_setWindowname, $name)
EndFunc

Func setCommand()
    $command = GUICtrlRead($tb_command)
    GuiCtrlSetData($lbl_setCommand, $command)
EndFunc

Func setDelay()
    $delay = GUICtrlRead($tb_delay)
    GuiCtrlSetData($lbl_setDelay, $delay)
EndFunc


Func doSleep()
    sleep($delay)
EndFunc


;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;The meat of the program
Func runProgram2()
    WinWaitActive ($lbl_setWindowname)

    While 1
        send($command)
        Sleep($delay)
    WEnd

EndFunc


;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Func runProgram()

While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        GUIDelete()
        ExitLoop

    Case $msg = $stop
        If $Busy Then $Busy = NOT $Busy
    ToolTip("")
    ExitLoop
    
    Case $msg = $run OR $Busy
        If NOT $Busy Then $Busy = 1
      ; do stuff until run is pressed
        $x = $x + 1
       ;ToolTip("$x = " & $x)
    send($command)
        Sleep($delay)
        
    Case Else
      ;;;
        
    EndSelect
WEnd
setVals()

EndFunc
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



GUIDelete()

Exit
Link to comment
Share on other sites

Guest Orlann

weee.. it works now (a little defiant on the STOP button) .. but it works. Works in target application it was designed for to :)))

Link to comment
Share on other sites

Look at this, It is untested but it should do what you want.

Add this in your Script

Global $break = 0
Func _break()
    $break = 1
EndFunc  ;==>_break

Change your RunProgram Function to

Func _runProgram()
    GUISetState(@SW_HIDE, $WinMain)
                Sleep(3000); to give you time change window to where you want
; it to send to        
    While 1
        send($command)
        Sleep($delay)
        If $break = 1 Then
            HotKeySet("{ESC}")
            $break = 0
            GUISetState(@SW_SHOW, $WinMain)
            ExitLoop
        EndIf
    WEnd
EndFunc

Change this

Case $msg = $run
      ;If $running = 0 Then
      ;    runProgram()
      ;Else
      ;    ExitLoop
      ;EndIf
      ;TogglePause()
            runProgram()

In to this

Case $msg = $run
          _runProgram()

This should my the gui Hide when you click run so that it can Send to some wheres else. Use the Esc key to stop the program and to my the Gui show again

Edited by quick_sliver007

.

Link to comment
Share on other sites

Guest Orlann

and call _break() via the stop button?

the addon/mod doesnt show recomended spot to call it. no time atm to test it.

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