Jump to content

Recommended Posts

Hello,

    I am attempting to create a simple program to help me with mundane tasks I do at work. Unfortunately most 50% of my job is repeating the same information over and over to keep everyone updated on our current progress for the day.

    What I would eventually like to accomplish is typing in some sort of message (Example: "PDP at 80% SL. Moved to AHOD) and have the message sent through communications so that everyone can see it and have repeat it X number of times every X minutes. (Obviously the time and minutes would be variable)

   However, I've started from the basic steps to and so far I am able to create a function to open notepad and send a simple key stroke and have it repeat 5 times with a delay in between. The issue I am seeing is that basically this function locks the program itself and no other functions can be executed. I need to be able to set up multiple codes sent out (IE Func1 sends #1 every 3 minutes, Func2 sends #2 every 1 minute, Func3 sends #3 every 10 minutes)

     Can anyone point me in the right direction for something to reference?

#include <GUIConstantsEx.au3>

HotKeySet("{Esc}", "_Exit")

Form()

Func Form()
    Local $hGUI = GUICreate("Form", 300, 300)

    $Labe1 = GUICtrlCreateLabel("Something", 10, 2, 50, 17)
    $Button01 = GUICtrlCreateButton("1", 10, 21, 25, 25)
    $Button02 = GUICtrlCreateButton("2", 10, 45, 25, 25)
    $Button03 = GUICtrlCreateButton("3", 10, 69, 25, 25)
    $Button04 = GUICtrlCreateButton("4", 10, 93, 25, 25)
    $Button05 = GUICtrlCreateButton("5", 10, 117, 25, 25)
    $Button06 = GUICtrlCreateButton("6", 10, 141, 25, 25)
    $Button07 = GUICtrlCreateButton("7", 10, 165, 25, 25)
    $Button08 = GUICtrlCreateButton("8", 10, 189, 25, 25)
    $Button09 = GUICtrlCreateButton("9", 10, 213, 25, 25)
    $Label1 = GUICtrlCreateLabel("Something", 70, 2, 50, 17)
    $Input01 = GUICtrlCreateInput("", 70, 21, 33, 21)
    $Input02 = GUICtrlCreateInput("", 70, 45, 33, 21)
    $Input03 = GUICtrlCreateInput("", 70, 69, 33, 21)
    $Input04 = GUICtrlCreateInput("", 70, 93, 33, 21)
    $Input05 = GUICtrlCreateInput("", 70, 117, 33, 21)
    $Input06 = GUICtrlCreateInput("", 70, 141, 33, 21)
    $Input07 = GUICtrlCreateInput("", 70, 165, 33, 21)
    $Input08 = GUICtrlCreateInput("", 70, 189, 33, 21)
    $Input09 = GUICtrlCreateInput("", 70, 213, 33, 21)
    Local $Button10= GUICtrlCreateButton("Start/Stop", 125,270, 85, 25)
    Local $Button11 = GUICtrlCreateButton("Close", 210, 270, 85, 25)

   GUISetState(@SW_SHOW, $hGUI)
   Local $iPID = 0
      While 1
         Switch GUIGetMsg()
###Button01###
      Case $Button01
         Run("notepad.exe")
         Sleep (3000)  ;long enough for me to click on the window
         While 1
            Send ("1")
            Sleep (550)
            Send ("1")
            Sleep (550)
            Send ("1")
            Sleep (550)
            Send ("1")
            Sleep (550)
            Send ("1")
            Sleep (5000)
         WEnd
###Button02###
            Sleep (3000)
            While 1
            Send ("2")
            Sleep (5000)
            WEnd
###Button03###
###Button04###
            Sleep (3000)
            While 1
            Send ("4")
            Sleep (5000)
            WEnd
###Button05###
###Button10###
         Case $Button10
###Button11###
         Case $GUI_EVENT_CLOSE, $Button11
            ExitLoop
         EndSwitch
      WEnd

    ; Delete the previous GUI and all controls.
    GUIDelete($hGUI)

    ; Close the Notepad process using the PID returned by Run.
    If $iPID Then ProcessClose($iPID)
    EndFunc   ;==>Form

 

Link to post
Share on other sites

What I would do is setup an ini file with all your messages in.  You can read the ini file every minute and if it is time, you send the message(s) and register the current time.  It would make your script WAY shorter. You simply have to modify the ini file and the script will adapt accordingly.  Let me know if you need help, I'll put a frame for you to start you up.

Edited by Nine
Link to post
Share on other sites

Try it :

#include <Constants.au3>
#include <Date.au3>
#include <Array.au3>

Global Const $INI_FILE = "Tasks.ini"

HotKeySet("{ESC}", _Exit)

CheckTasks() ; check now
AdlibRegister (CheckTasks, 30000) ; check thereafter every 30 secs

While True
  Sleep (1000)
WEnd

Func _Exit ()
  Exit
EndFunc

Func CheckTasks ()
  Local $aTask = IniReadSectionNames($INI_FILE), $sMessage, $iDelay, $sTime
  If @error Then Exit MsgBox ($MB_SYSTEMMODAL,"","Bad ini file")
  For $i = 1 to $aTask[0]
    $sMessage = IniRead($INI_FILE, $aTask[$i], "Message", "")
    If $sMessage = "" Then ContinueLoop
    $iDelay = Number(IniRead($INI_FILE, $aTask[$i], "Delay", "0"))
    If $iDelay = 0 Then ContinueLoop
    $sTime = IniRead($INI_FILE, $aTask[$i], "Time", "")
    If $sTime = "" Or _DateDiff ("n", StringReplace($sTime, "-", "/"),StringReplace(_Now(), "-", "/")) >= $iDelay Then
      ; do your stuff here
      ConsoleWrite (_Now() & " " & $sMessage & @CRLF)
      IniWrite($INI_FILE, $aTask[$i], "Time", _Now()) ; create or update time entry
    EndIf
  Next
EndFunc

I attached the ini file.  Note the time entry is not necessary at first, but you can put a time for the future if need to.

Tasks.ini

Link to post
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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...