[HELP] Macro: Spam Text

05/08/2009 20:13 s8rkjosh#1
I have help spam for me in-game. Not sure how I write to different key named msg1...msg6 ini file. I pass global variable but become local in _txtwrite() function. When I pass 1 more, it no change. Still write same key as pass by first variable and go through condition. Here is code to help through this struggle? And maybe figure easy way to write code in other way?

PHP Code:
#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#Include <GuiButton.au3>
#Include <GuiEdit.au3>

Opt("GUICoordMode"1)
Opt("GUIOnEventMode"1) ; Change to OnEvent Mode

Create GUI Window
$MainWindow 
GUICreate("sendtxt (LC)"23090)


Create Menu
$File 
GUICtrlCreateMenu("File")
$Close GUICtrlCreateMenuItem("Close"$File)
GUICtrlSetOnEvent($Close"_Close") ; GUICtrlSetOnEvent waits for user's input. Once received, it will then run the assigned function
$Edit = GUICtrlCreateMenu("Edit")
$Msg01m = GUICtrlCreateMenuItem("MSG01", $Edit)
GUICtrlSetOnEvent($Msg01m, "_msg01")
$Msg02m = GUICtrlCreateMenuItem("MSG02", $Edit)
GUICtrlSetOnEvent($Msg02m, "_msg02")
$Msg03m = GUICtrlCreateMenuItem("MSG03", $Edit)
GUICtrlSetOnEvent($Msg03m, "_msg03")
$Msg04m = GUICtrlCreateMenuItem("MSG04", $Edit)
GUICtrlSetOnEvent($Msg04m, "_msg04")
$Msg05m = GUICtrlCreateMenuItem("MSG05", $Edit)
GUICtrlSetOnEvent($Msg05m, "_msg05")
$Msg06m = GUICtrlCreateMenuItem("MSG06", $Edit)
GUICtrlSetOnEvent($Msg06m, "_msg06")
$About = GUICtrlCreateMenu("About")
$Info = GUICtrlCreateMenuItem("Info", $About)
GUICtrlSetOnEvent($Info, "_Info")
$Help = GUICtrlCreateMenuItem("Help File", $About)
GUICtrlSetOnEvent($Help, "_Help")

; Create MSG Box
$Msg01 = GUICtrlCreateButton("MSG01", 5, -1+5)
GUICtrlSetOnEvent($Msg01, "_msg01")
$Msg02 = GUICtrlCreateButton("MSG02", 55, -1+5)
GUICtrlSetOnEvent($Msg02, "_msg01")
$Msg03 = GUICtrlCreateButton("MSG03", 105, -1+5)
GUICtrlSetOnEvent($Msg03, "_msg01")
$Msg04 = GUICtrlCreateButton("MSG04", 5, -1+40)
GUICtrlSetOnEvent($Msg04, "_msg01")
$Msg05 = GUICtrlCreateButton("MSG05", 55, -1+40)
GUICtrlSetOnEvent($Msg05, "_msg01")
$Msg06 = GUICtrlCreateButton("MSG06", 105, -1+40)
GUICtrlSetOnEvent($Msg06, "_msg01")
$Save = GUICtrlCreateButton("SAVE", 155, -1+5, 60, 60)
GUICtrlSetTip($Save, "Save Changes")
GUICtrlSetOnEvent($Save, "_Save")


; Set state to display GUI Window
GUISetState(@SW_SHOW)

; Wait for user'
s input
While (1)
    
Sleep(1000)
WEnd


Func _main_edit_ctrl
()
    Global 
$EditWindow GUICreate("Msg01"200150, Default, Default, Default, Default, $MainWindow)
    
GUISetState(@SW_SHOW)
    
$txtedit GUICtrlCreateEdit("", -1, -1200100$ES_MULTILINE)
    
$txteditOK GUICtrlCreateButton("OK!"12115175)
    Do
        Global 
$txtRead GUICtrlRead($txtedit)
    
Until _GUICtrlButton_GetState($txteditOK)
EndFunc
; function($key) <== don't forget
Func _txtwrite()
;    $FileSize = _GUICtrlEdit_GetTextLen($txtRead)
;    If $FileSize <= 249 Then
        If $key = 1 Then
            IniWrite(@ScriptDir & "\sendtxt.ini","TEXT","msg1", $txtRead)
            GUIDelete($EditWindow)
        ElseIf $key = 2 Then
            IniWrite(@ScriptDir & "\sendtxt.ini","TEXT","msg2", $txtRead)
            GUIDelete($EditWindow)
        ElseIf $key = 3 Then
            IniWrite(@ScriptDir & "\sendtxt.ini","TEXT","msg3", $txtRead)
            GUIDelete($EditWindow)
        ElseIf $key = 4 Then
            IniWrite(@ScriptDir & "\sendtxt.ini","TEXT","msg4", $txtRead)
            GUIDelete($EditWindow)
        ElseIf $key = 5 Then
            IniWrite(@ScriptDir & "\sendtxt.ini","TEXT","msg5", $txtRead)
            GUIDelete($EditWindow)
        ElseIf $key = 6 Then
            IniWrite(@ScriptDir & "\sendtxt.ini","TEXT","msg6", $txtRead)
            GUIDelete($EditWindow)
        Else
            ;MsgBox(0, "DENIED!", "Message cannot be longer than 250: " &$FileSize)
        EndIf
;    EndIf
EndFunc

        
    
; Every _msgxx function writes saved data to .ini
Func _msg01()
    $key = 1
    _main_edit_ctrl()
EndFunc
Func _msg02()
    $key = 2
    _main_edit_ctrl()
EndFunc
Func _msg03()
    $key = 3
    _main_edit_ctrl()
EndFunc
Func _msg04()
    $key = 4
    _main_edit_ctrl()
EndFunc
Func _msg05()
    $key = 5
    _main_edit_ctrl()
EndFunc
Func _msg06()
    $key = 6
    _main_edit_ctrl()
EndFunc

; Save Changes
Func _Save()
    
EndFunc

; Information about the program
Func _Info()
    
EndFunc

; Help File on how to Operate
Func _Help()
    
EndFunc

; Exit
Func _Close()
    If @GUI_WINHANDLE = $MainWindow Then
        Exit
    EndIf
EndFunc 
05/15/2009 14:41 Pblx#2
Code:
#include <GUIConstantsEx.au3>
#include <EditConstants.au3>


;Variables to edit
Global $windowTitle = "World of Warcraft" ;send message to this window




;--------------------
Global $GUI_EditWindow ;hwdn of edit window
Global $FileName = @ScriptDir & "\sendtxt.ini"
Global $lastCtrlId
Global $txtedit


Opt("GUIOnEventMode", 1) ; Change to OnEvent Mode

; Create GUI Window
Global $GUI = GUICreate("sendtxt (LC)", 230, 90)

; Menu File
$File = GUICtrlCreateMenu("File")
$Close = GUICtrlCreateMenuItem("Close", $File)

; Menu Edit
$Edit = GUICtrlCreateMenu("Edit")
$Msg01m = GUICtrlCreateMenuItem("MSG01", $Edit)
$Msg02m = GUICtrlCreateMenuItem("MSG02", $Edit)
$Msg03m = GUICtrlCreateMenuItem("MSG03", $Edit)
$Msg04m = GUICtrlCreateMenuItem("MSG04", $Edit)
$Msg05m = GUICtrlCreateMenuItem("MSG05", $Edit)
$Msg06m = GUICtrlCreateMenuItem("MSG06", $Edit)

; Menu About
$About = GUICtrlCreateMenu("About")
$Info = GUICtrlCreateMenuItem("Info", $About)
$Help = GUICtrlCreateMenuItem("Help File", $About)

;set Events for Menu
GUICtrlSetOnEvent($Close, "_Close") ; GUICtrlSetOnEvent waits for user's input. Once received, it will then run the assigned function
GUICtrlSetOnEvent($Msg01m, "_msgEdit")
GUICtrlSetOnEvent($Msg02m, "_msgEdit")
GUICtrlSetOnEvent($Msg03m, "_msgEdit")
GUICtrlSetOnEvent($Msg04m, "_msgEdit")
GUICtrlSetOnEvent($Msg05m, "_msgEdit")
GUICtrlSetOnEvent($Msg06m, "_msgEdit")
GUICtrlSetOnEvent($Info, "_Info")
GUICtrlSetOnEvent($Help, "_Help")



; Buttons
Global $Msg01 = GUICtrlCreateButton("MSG01", 5, -1+5)
Global $Msg02 = GUICtrlCreateButton("MSG02", 55, -1+5)
Global $Msg03 = GUICtrlCreateButton("MSG03", 105, -1+5)
Global $Msg04 = GUICtrlCreateButton("MSG04", 5, -1+40)
Global $Msg05 = GUICtrlCreateButton("MSG05", 55, -1+40)
Global $Msg06 = GUICtrlCreateButton("MSG06", 105, -1+40)


; set Events for Buttons
GUICtrlSetOnEvent($Msg01, "_msgSend")
GUICtrlSetOnEvent($Msg02, "_msgSend")
GUICtrlSetOnEvent($Msg03, "_msgSend")
GUICtrlSetOnEvent($Msg04, "_msgSend")
GUICtrlSetOnEvent($Msg05, "_msgSend")
GUICtrlSetOnEvent($Msg06, "_msgSend")



; Set state to display GUI Window
_SetButtonState()
GUISetState(@SW_SHOW)
GUISetOnEvent($GUI_EVENT_CLOSE,"_Close")

; Wait for user's input
While 1
   sleep(1000)
WEnd


        
    
; Send the message to the WindowTitle with ControlSend
Func _msgSend()
   Local $message = IniRead($FileName, "Text", GUICtrlRead(@GUI_CtrlId,1), "")
   if $message Then 
      ControlSend($windowTitle, "", 0, $message)
   Else
      _msgEdit()
   EndIf
EndFunc


; Edit the Message, get last Control Id
Func _msgEdit()
   $lastCtrlId = @GUI_CtrlId
   _editCtrl()
EndFunc


; Edit MSG with a new GUI
Func _editCtrl()
   GUISetState(@SW_DISABLE, $GUI) ;disable main gui
   
   $GUI_EditWindow = GUICreate("Edit " & GUICtrlRead($lastCtrlId, 1), 200, 150)
   $txtedit = GUICtrlCreateEdit(IniRead($FileName, "Text", GUICtrlRead(@GUI_CtrlId,1), ""), -1, -1, 200, 100, $ES_MULTILINE)
   $txteditOK = GUICtrlCreateButton("OK!", 12, 115, 175)
   GUICtrlSetOnEvent($txteditOK, "_SaveMsg")
   
   GUISetState(@SW_SHOW)
EndFunc


; Save Changes
Func _SaveMsg()
   IniWrite($FileName, "Text", GUICtrlRead($lastCtrlId,1), GUICtrlRead($txtedit))
   
   ;set state of buttons
   GUICtrlSetState($lastCtrlId,$GUI_ENABLE)
   _SetButtonState()
   _Close()
EndFunc


; Information about the program
Func _Info()
   MsgBox(64,"Info","edit by PiroX - www.PiroxBots.com")
EndFunc

; Help File on how to Operate
Func _Help()
    
EndFunc

; Exit & GuiDelete
Func _Close()
   if @GUI_WinHandle = $GUI Then
      Exit
   Else
      GUIDelete($GUI_EditWindow)
      GUISetState(@SW_ENABLE,$GUI)
      WinActivate($GUI)
   EndIf
EndFunc 

Func _SetButtonState()
   if not IniRead($FileName, "Text", GUICtrlRead($Msg01,1), "") Then GUICtrlSetState($Msg01, $GUI_DISABLE)
   if not IniRead($FileName, "Text", GUICtrlRead($Msg02,1), "") Then GUICtrlSetState($Msg02, $GUI_DISABLE)
   if not IniRead($FileName, "Text", GUICtrlRead($Msg03,1), "") Then GUICtrlSetState($Msg03, $GUI_DISABLE)
   if not IniRead($FileName, "Text", GUICtrlRead($Msg04,1), "") Then GUICtrlSetState($Msg04, $GUI_DISABLE)
   if not IniRead($FileName, "Text", GUICtrlRead($Msg05,1), "") Then GUICtrlSetState($Msg05, $GUI_DISABLE)
   if not IniRead($FileName, "Text", GUICtrlRead($Msg06,1), "") Then GUICtrlSetState($Msg06, $GUI_DISABLE)
EndFunc