Sign in to follow this  
Followers 0
xanathos

Script slow to exit

5 posts in this topic

#1 ·  Posted (edited)

Hello everyone, I have 2 problems with my script, first it eats CPU like crazy, but I know that's because I didn't put a sleep in the loop, I wanna solve the other problem first, the script is hella slow to quit it takes like 10-15 seconds, sometimes even more to exit!

Here is my script, I know its a mess but I'm new to AutoIT

;----------------------------------------------------------------------------------------------------
; INCLUDES
;----------------------------------------------------------------------------------------------------
#include <StaticConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <FileConstants.au3>
#include <Array.au3>
#include <File.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
;----------------------------------------------------------------------------------------------------
; GLOBALS
;----------------------------------------------------------------------------------------------------
Global $delayTimer = TimerInit()
Global $text
Global $hwnd = WinGetHandle("aMSN")
Global $hwnd2 = WiNGetHandle("Notepad++")
Global $IniFile = @ScriptDir & "Config.ini"
Global $ControlID[10]
Global $ProgramFilesDir = EnvGet('ProgramFiles(x86)') ; for 64bit Win it will return a valid path.
if not $ProgramFilesDir then $ProgramFilesDir = @ProgramFilesDir ; for 32bit Win this will "repair" the broken return from above.
;----------------------------------------------------------------------------------------------------
Global $UpdateEvery = 5000 ; milliseconds
Global $CheckEvery = 10000 ; milliseconds
;----------------------------------------------------------------------------------------------------
; GUI
;----------------------------------------------------------------------------------------------------
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 1093, 340, 207, 430)
$MenuItem1 = GUICtrlCreateMenu("Fichier")
$MenuItem2 = GUICtrlCreateMenuItem("Ouvrir", $MenuItem1)
$MenuItem3 = GUICtrlCreateMenuItem("Sauvegarder", $MenuItem1)
$MenuItem6 = GUICtrlCreateMenuItem("Quitter", $MenuItem1)
$MenuItem4 = GUICtrlCreateMenu("Aide")
$MenuItem5 = GUICtrlCreateMenuItem("A propos", $MenuItem4)
$Edit1 = GUICtrlCreateEdit("", 8, 8, 1073, 153, $ES_READONLY)
GUICtrlSetColor(-1, 0xA0FFA0)
GUICtrlSetBkColor(-1, 0x202943)
GUICtrlSetFont(-1, 8, 400, 0, "Tahoma")
$Group1 = GUICtrlCreateGroup("Macro 1:", 8, 168, 209, 137)
GUICtrlSetColor(-1, 0xFF0000)
$addbtn = GUICtrlCreateButton("+", 160, 184, 25, 17)
$Input1 = GUICtrlCreateInput("", 24, 208, 177, 21)
$Input2 = GUICtrlCreateInput("", 24, 256, 177, 21)
$ControlID[1] = $Input2
$Label1 = GUICtrlCreateLabel("Si trouve:", 24, 192, 49, 15)
GUICtrlSetColor(-1, 0xFF0000)
$Label2 = GUICtrlCreateLabel("Répondre:", 24, 240, 54, 15)
GUICtrlSetColor(-1, 0xFF0000)
$Button1 = GUICtrlCreateCheckbox("Démarrer", 144, 280, 57, 17, $BS_PUSHLIKE)
GUICtrlSetBkColor(-1, 0xFF0000)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("Macro 2:", 224, 168, 209, 137)
GUICtrlSetColor(-1, 0x0000FF)
$Input3 = GUICtrlCreateInput("", 240, 208, 177, 21)
$ControlID[2] = $Input3
$Input4 = GUICtrlCreateInput("", 240, 256, 177, 21)
$ControlID[3] = $Input4
$Label3 = GUICtrlCreateLabel("Si trouve:", 240, 192, 49, 15)
GUICtrlSetColor(-1, 0x0000FF)
$Label4 = GUICtrlCreateLabel("Répondre:", 240, 240, 54, 15)
GUICtrlSetColor(-1, 0x0000FF)
$Button2 = GUICtrlCreateCheckbox("Démarrer", 360, 280, 57, 17, $BS_PUSHLIKE)
GUICtrlSetColor(-1, 0x0000FF)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group3 = GUICtrlCreateGroup("Macro 3:", 440, 168, 209, 137)
GUICtrlSetColor(-1, 0x008000)
$Input5 = GUICtrlCreateInput("", 456, 208, 177, 21)
$ControlID[4] = $Input5
$Input6 = GUICtrlCreateInput("", 456, 256, 177, 21)
$ControlID[5] = $Input6
$Label5 = GUICtrlCreateLabel("Si trouve:", 456, 192, 49, 15)
GUICtrlSetColor(-1, 0x008000)
$Label6 = GUICtrlCreateLabel("Répondre:", 456, 240, 54, 15)
GUICtrlSetColor(-1, 0x008000)
$Button3 = GUICtrlCreateCheckbox("Démarrer", 576, 280, 57, 17, $BS_PUSHLIKE)
GUICtrlSetColor(-1, 0x008000)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group4 = GUICtrlCreateGroup("Macro 4:", 656, 168, 209, 137)
GUICtrlSetColor(-1, 0x800080)
$Input7 = GUICtrlCreateInput("", 672, 208, 177, 21)
$ControlID[6] = $Input7
$Input8 = GUICtrlCreateInput("", 672, 256, 177, 21)
$ControlID[7] = $Input8
$Label7 = GUICtrlCreateLabel("Si trouve:", 672, 192, 49, 15)
GUICtrlSetColor(-1, 0x800080)
$Label8 = GUICtrlCreateLabel("Répondre:", 672, 240, 54, 15)
GUICtrlSetColor(-1, 0x800080)
$Button4 = GUICtrlCreateCheckbox("Démarrer", 792, 280, 57, 17, $BS_PUSHLIKE)
GUICtrlSetColor(-1, 0x800080)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group5 = GUICtrlCreateGroup("Macro 5:", 872, 168, 209, 137)
GUICtrlSetColor(-1, 0xFFFF00)
$Input9 = GUICtrlCreateInput("", 888, 208, 177, 21)
$ControlID[8] = $Input9
$Input10 = GUICtrlCreateInput("", 888, 256, 177, 21)
$ControlID[9] = $Input10
$Label9 = GUICtrlCreateLabel("Si trouve:", 888, 192, 49, 15)
GUICtrlSetColor(-1, 0xFFFF00)
$Label10 = GUICtrlCreateLabel("Répondre:", 888, 240, 54, 15)
GUICtrlSetColor(-1, 0xFFFF00)
$Button5 = GUICtrlCreateCheckbox("Démarrer", 1008, 280, 57, 17, $BS_PUSHLIKE)
GUICtrlSetColor(-1, 0xFFFF00)
GUICtrlCreateGroup("", -99, -99, 1, 1)
;~ For $i = 0 To 9
;~   GUICtrlSetData($ControlID[$i], IniRead($IniFile, "Macro1", $i, ""))
;~ Next
GUICtrlSetData($Input1, IniRead($IniFile, "Macro 1", "Mot-Clef", ""))
GUICtrlSetData($Input2, IniRead($IniFile, "Macro 1", "Réponse", ""))
GUICtrlSetData($Input3, IniRead($IniFile, "Macro 2", "Mot-Clef", ""))
GUICtrlSetData($Input4, IniRead($IniFile, "Macro 2", "Réponse", ""))
GUICtrlSetData($Input5, IniRead($IniFile, "Macro 3", "Mot-Clef", ""))
GUICtrlSetData($Input6, IniRead($IniFile, "Macro 3", "Réponse", ""))
GUICtrlSetData($Input7, IniRead($IniFile, "Macro 4", "Mot-Clef", ""))
GUICtrlSetData($Input8, IniRead($IniFile, "Macro 4", "Réponse", ""))
GUICtrlSetData($Input9, IniRead($IniFile, "Macro 5", "Mot-Clef", ""))
GUICtrlSetData($Input10, IniRead($IniFile, "Macro 5", "Réponse", ""))
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###



;----------------------------------------------------------------------------------------------------
; MAIN LOOP
;----------------------------------------------------------------------------------------------------
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
  Case $GUI_EVENT_CLOSE
   Exit
  Case $Button1
   If GuiCtrlRead($Button1) = $GUI_CHECKED then
    Adlibregister("Macro1", 5000)
    GUICtrlSetData($Button1, "Arrêter")
   EndIf
   If GuiCtrlRead($Button1) = $GUI_UNCHECKED then
    Adlibunregister("Macro1")
    GuiCtrlSetData($Button1, "Démarrer")
   EndIf
  Case $MenuItem2
   $file = FileOpenDialog("Ouvrir Fichier...", @ScriptDir, "Ini (*.ini)")
   GUICtrlSetData($Input1, IniRead($file, "Macro 1", "Mot-Clef", ""))
   GUICtrlSetData($Input2, IniRead($file, "Macro 1", "Réponse", ""))
   GUICtrlSetData($Input3, IniRead($file, "Macro 2", "Mot-Clef", ""))
   GUICtrlSetData($Input4, IniRead($file, "Macro 2", "Réponse", ""))
   GUICtrlSetData($Input5, IniRead($file, "Macro 3", "Mot-Clef", ""))
   GUICtrlSetData($Input6, IniRead($file, "Macro 3", "Réponse", ""))
   GUICtrlSetData($Input7, IniRead($file, "Macro 4", "Mot-Clef", ""))
   GUICtrlSetData($Input8, IniRead($file, "Macro 4", "Réponse", ""))
   GUICtrlSetData($Input9, IniRead($file, "Macro 5", "Mot-Clef", ""))
   GUICtrlSetData($Input10, IniRead($file, "Macro 5", "Réponse", ""))
  Case $MenuItem6
   Exit
  Case $MenuItem3
   $file = FileSaveDialog("Sauvegarder Fichier...", @Scriptdir, "Ini (*.ini)", 16, "" & ".ini")
;~ $file = _WinAPI_GetSaveFileName("Sélectionnez un fichier","Ini (*.ini)", @ScriptDir, "", "ini")
;~  For $i = 0 To 9
   IniWrite($file, "Macro 1", "Mot-Clef", GUICtrlRead($Input1))
   IniWrite($file, "Macro 1", "Réponse", GUICtrlRead($Input2))
  
   IniWrite($file, "Macro 2", "Mot-Clef", GUICtrlRead($Input3))
   IniWrite($file, "Macro 2", "Réponse", GUICtrlRead($Input4))
  
   IniWrite($file, "Macro 3", "Mot-Clef", GUICtrlRead($Input5))
   IniWrite($file, "Macro 3", "Réponse", GUICtrlRead($Input6))
  
   IniWrite($file, "Macro 4", "Mot-Clef", GUICtrlRead($Input7))
   IniWrite($file, "Macro 4", "Réponse", GUICtrlRead($Input8))
  
   IniWrite($file, "Macro 5", "Mot-Clef", GUICtrlRead($Input9))
   IniWrite($file, "Macro 5", "Réponse", GUICtrlRead($Input10))
;~   Next
  Case $MenuItem5
   Switch MsgBox(4, "Plus de poudre blanche", "T'es sur mon pénis? Je pense que:")
    Case 6
     MsgBox(0, "Ok ok", "Han, t'as compris l'putain d'plan de G&G")
    Case 7
     MsgBox(0, "Eteins l'truc", "J'éteins l'putain d'truc, allez putain!")
     ShellExecute("http://www.youtube.com/watch?v=ev-VCoMCTlU&t=0m20s")
     Exit
   EndSwitch
EndSwitch
If ProcessExists("amsn.exe") Then
  OnInit()
Else
  OnUpdate()
EndIf
WEnd
;----------------------------------------------------------------------------------------------------
; FUNCTIONS
;----------------------------------------------------------------------------------------------------
Func OnInit()
Dim $FileArray[1]
Dim $FileNew[1]
_FileReadToArray($ProgramFilesDir & "MessengerChat.log", $FileArray)
For $i = 1 To $FileArray[0]
  If StringInStr($FileArray[$i], "says") Then
   _ArrayAdd($FileNew, $FileArray[$i])
  EndIf
Next
_ArrayDelete($FileNew, 0)
_FileWriteFromArray("Test.txt", $FileNew)
_FileWriteFromArray("Log.txt", $FileNew)
GUICtrlSetData($Edit1, FileRead("Log.txt"))
EndFunc   ;==>OnInit
Func OnUpdate()
If TimerDiff($delayTimer) > $UpdateEvery Then
  $delayTimer = TimerInit()
  OnInit()
EndIf
EndFunc   ;==>OnUpdate
Func Macro1()
$search = StringInStr(GuiCtrlRead($Edit1), GuiCtrlRead($Input1))
If $search <> 0 then
;~  Msgbox(0, "", GuiCtrlRead($Input1) & " trouvé")
;~  Send("{LWINDOWN}{END}{LWINUP}")
  ControlClick($hwnd2, "", "[Class:Button; INSTANCE:133]")
;~  sleep(3000)
  ControlSend($hwnd, "", "", "{END}")
  Opt("SendKeyDelay", 100)
  ControlSend($hwnd, "", "", GuiCtrlRead($Input2))
  ControlClick($hwnd2, "", "[Class:Button; INSTANCE:133]")
  FileDelete($ProgramFilesDir & "MessengerChat.log")
  FileDelete("Test.txt")
EndIf
EndFunc   ;==>Macro1
Edited by xanathos

Share this post


Link to post
Share on other sites



bump

Share this post


Link to post
Share on other sites

Xanathos

Not the help you may expected but i tested your script,although i don't know French i played with the buttons it opened a you tube page etc. Didn't noticed any intense cpu use. and the script exited instantly, with no delay.

I am on XP sp3 512mb.


[font="verdana, geneva, sans-serif"] [/font]

Share this post


Link to post
Share on other sites

Lets see....

If ProcessExists("amsn.exe") Then
  OnInit()

A very slow function running all the time (if amsn.exe is running). Could that be your problem? Try it without amsn running.

Share this post


Link to post
Share on other sites

Lets see....

If ProcessExists("amsn.exe") Then
  OnInit()

A very slow function running all the time (if amsn.exe is running). Could that be your problem? Try it without amsn running.

I thought so too, disabled it, no luck it still takes ages to exit, also I'm running Windows 7 64 bit, it could be why?

Share this post


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
Sign in to follow this  
Followers 0