Jump to content

Save GUICtrlCreateEdit contents on $GUI_EVEN_CLOSE to a .txt file


Recommended Posts

I want to know how to save the content of a control edit to a .txt file, on exit or on button click, doesn't matter.

This is what I have so far.

Please note, this it's not for a game, it's for a software named dota keys, I've posted another tread and confusion arise because the path include "games", but it's not game automation...

#include "macros.txt"
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>

$mainwindow = GUICreate("Options", 440, 333)
GUICtrlCreateLabel("Set the default macros.", 30, 10)
GUICtrlCreateEdit("", 30, 30, 412, 20)
GUICtrlCreateEdit("", 30, 60, 412, 20)
GUICtrlCreateEdit("", 30, 90, 412, 20)
GUICtrlCreateEdit("", 30, 120, 412, 20)
GUISwitch($mainwindow)
GUISetState(@SW_SHOW)
While 1
$msg = GUIGetMsg(1)

Select
Case $msg[0] = $GUI_EVENT_CLOSE And $msg[1] = $mainwindow
ExitLoop
EndSelect
WEnd

And the macros.txt content

$f3 = "miss"
$f4 = "re"
$f5 = "b"
$f6 = "push"

and the other script that reads the variables from macros.txt

#include "macros.txt"
Run("D:gamesWarcraft IIIdk1.4-0.2.2dotakeys.exe")
   WinWaitActive("DotaKeys v1.4-0.2.8")
   Sleep(1000)
   ControlClick("DotaKeys v1.4-0.2.8", "", 6) ;activates dota keys
   Sleep(100)
   If ControlGetText("DotaKeys v1.4-0.2.8", "", 17) == $f3 Then ;sets F3 to "miss"
Sleep(100)
   Else
ControlSetText("DotaKeys v1.4-0.2.8", "", 17, $f3)
   EndIf
If ControlGetText("DotaKeys v1.4-0.2.8", "", 18) == $f4 Then ;sets F4 to "re"
Sleep(100)
   Else
ControlSetText("DotaKeys v1.4-0.2.8", "", 18, $f4)
   EndIf
   If ControlGetText("DotaKeys v1.4-0.2.8", "", 19) == $f5 Then ;sets F5 to "b"
Sleep(100)
   Else
ControlSetText("DotaKeys v1.4-0.2.8", "", 19, $f5)
   EndIf
If ControlGetText("DotaKeys v1.4-0.2.8", "", 20) == $f6 Then ;sets F6 to "push"
Sleep(100)
   Else
ControlSetText("DotaKeys v1.4-0.2.8", "", 20, $f6)
   EndIf
   Sleep(100)
   WinSetState("DotaKeys v1.4-0.2.8", "", @SW_MINIMIZE)
   Sleep(500)

Run("D:gamesWarcraft IIIauto joinerAuto-Joiner.exe")
   WinWaitActive("hbm Garena Auto-Joiner 4.9.6.2 (120518)")
   Sleep(5000)
   WinWaitActive("Garena Plus (Beta) - SilverJin")
   Sleep(500)
   WinActivate("hbm Garena Auto-Joiner 4.9.6.2 (120518)")
   WinWaitActive("hbm Garena Auto-Joiner 4.9.6.2 (120518)")
   Sleep(100)
   ControlClick("hbm Garena Auto-Joiner 4.9.6.2 (120518)", "", 1001)
   Sleep(300)
Edited by silvermirai
Link to comment
Share on other sites

Assuming your code works the way you want and all you want to do is read the edit controls and write them to a file before exiting, you just need to insert a little code before exiting. Also, to read the edits, you need to assign them variable names ($Edit1, $Edit2, etc.).

#include "macros.txt"
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>

$mainwindow = GUICreate("Options", 440, 333)
GUICtrlCreateLabel("Set the default macros.", 30, 10)
$Edit1 = GUICtrlCreateEdit("", 30, 30, 412, 20)
$Edit2 = GUICtrlCreateEdit("", 30, 60, 412, 20)
$Edit3 = GUICtrlCreateEdit("", 30, 90, 412, 20)
$Edit4 = GUICtrlCreateEdit("", 30, 120, 412, 20)
GUISwitch($mainwindow)
GUISetState(@SW_SHOW)

While 1
$msg = GUIGetMsg(1)
Select
Case $msg[0] = $GUI_EVENT_CLOSE And $msg[1] = $mainwindow
FileWrite("filename.txt", GUICtrlRead($Edit1) & @CRLF)
FileWrite("filename.txt", GUICtrlRead($Edit2) & @CRLF)
FileWrite("filename.txt", GUICtrlRead($Edit3) & @CRLF)
FileWrite("filename.txt", GUICtrlRead($Edit4) & @CRLF)
ExitLoop
EndSelect
WEnd
Link to comment
Share on other sites

Thank you for your help, my gui script works fine, I used _FileWriteToLine.

Now I need to make the gui read from the existing data from text file and display each line on control edit.

Then I need to write script for the button "save without exiting" to exit when pressed, I don't know how to make a button do something when it's pressed.

Also small inconvenience, I can't click on the control edit, I can only use tab to select and edit them.

Please help me if you can.

Here is a image of the gui.

http://www.picz.ro/show-image.php?id=96264469cac3adcb717d3c5f2cf565a2

And here is the GUI script.

#include 
#include 
#include 

local $msg

GUICreate("Macros", 320, 185)
GUISetState(@SW_SHOW)

GUICtrlCreateLabel("F3", 5, 35) ;f3, f4, f5, f6 text labels
GUICtrlCreateLabel("F4", 5, 65)
GUICtrlCreateLabel("F5", 5, 95)
GUICtrlCreateLabel("F6", 5, 125)

GUICtrlCreateButton("Exit without saving", 110, 150)

$f3edit = GUICtrlCreateEdit("", 25, 30, 300, 20) ;control edits that takes input from user
$f4edit = GUICtrlCreateEdit("", 25, 60, 300, 20)
$f5edit = GUICtrlCreateEdit("", 25, 90, 300, 20)
$f6edit = GUICtrlCreateEdit("", 25, 120, 300, 20)


While 1
$msg = GUIGetMsg()

If $msg = $GUI_EVENT_CLOSE Then ExitLoop
_FileWriteToLine("test.txt", 1, GUICtrlRead($f3edit), 1)
_FileWriteToLine("test.txt", 2, GUICtrlRead($f4edit), 1)
_FileWriteToLine("test.txt", 3, GUICtrlRead($f5edit), 1)
_FileWriteToLine("test.txt", 4, GUICtrlRead($f6edit), 1)
WEnd
GUIDelete()
Link to comment
Share on other sites

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>
#include <file.au3>

local $msg

GUICreate("Macros", 320, 185)
GUISetState(@SW_SHOW)

GUICtrlCreateLabel("F3", 5, 35) ;f3, f4, f5, f6 text labels
GUICtrlCreateLabel("F4", 5, 65)
GUICtrlCreateLabel("F5", 5, 95)
GUICtrlCreateLabel("F6", 5, 125)

$button = GUICtrlCreateButton("Exit without saving", 110, 150) ; to use this button, you must assign a variable

$f3edit = GUICtrlCreateEdit("", 25, 30, 300, 20) ;control edits that takes input from user
$f4edit = GUICtrlCreateEdit("", 25, 60, 300, 20)
$f5edit = GUICtrlCreateEdit("", 25, 90, 300, 20)
$f6edit = GUICtrlCreateEdit("", 25, 120, 300, 20)


While 1
$msg = GUIGetMsg()

If $msg = $GUI_EVENT_CLOSE Then
_FileCreate("test.txt")
_FileWriteToLine("test.txt", 1, GUICtrlRead($f3edit), 1)
_FileWriteToLine("test.txt", 2, GUICtrlRead($f4edit), 1)
_FileWriteToLine("test.txt", 3, GUICtrlRead($f5edit), 1)
_FileWriteToLine("test.txt", 4, GUICtrlRead($f6edit), 1)
ExitLoop
Endif

If $msg = $button Then ; If button is pushed, exit without saving to text file
    ExitLoop
EndIf

WEnd
GUIDelete()

Edited by abberration
Link to comment
Share on other sites

Thank you very much !

Now I know how to make buttons do stuff.

Everything works fine, I've added 2 shortcuts 2 buttons, and the 4 control edit now reads the 4 lines

The only problem now is that I don't know how to make the 4 instances of control edit to be in focus when I click on them.

Please help xD

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>
#include <file.au3>

local $msg

GUICreate("Macros", 320, 185)
GUISetState(@SW_SHOW)

$line1 = FileReadLine("test.txt", 1) ;reads the controls into variables from txt file
$line2 = FileReadLine("test.txt", 2)
$line3 = FileReadLine("test.txt", 3)
$line4 = FileReadLine("test.txt", 4)

GUICtrlCreateLabel("Hotkeys: alt + z = Save and exit     alt + x = Save without exiting", 5, 5, 300)

GUICtrlCreateLabel("F3", 5, 35) ;f3, f4, f5, f6 text labels 
GUICtrlCreateLabel("F4", 5, 65)
GUICtrlCreateLabel("F5", 5, 95)
GUICtrlCreateLabel("F6", 5, 125)

$swe = GUICtrlCreateButton("Save and exit", 235, 150) 
$closeButton = GUICtrlCreateButton("Close", 10, 150)

$f3edit = GUICtrlCreateEdit("", 25, 30, 300, 20) ;control edits that takes input from user
$f4edit = GUICtrlCreateEdit("", 25, 60, 300, 20)
$f5edit = GUICtrlCreateEdit("", 25, 90, 300, 20)
$f6edit = GUICtrlCreateEdit("", 25, 120, 300, 20)

ControlSetText("", "", $f3edit, $line1) ; reads from txt and displays on controls
ControlSetText("", "", $f4edit, $line2)
ControlSetText("", "", $f5edit, $line3)
ControlSetText("", "", $f6edit, $line4)

HotKeySet("!x", "swe") ;save without Exit

Func swe()
   Exit
EndFunc

HotKeySet("!z", "sae")

Func sae()
   _FileWriteToLine("test.txt", 1, GUICtrlRead($f3edit), 1)
   _FileWriteToLine("test.txt", 2, GUICtrlRead($f4edit), 1) 
   _FileWriteToLine("test.txt", 3, GUICtrlRead($f5edit), 1)
   _FileWriteToLine("test.txt", 4, GUICtrlRead($f6edit), 1)
   Exit
EndFunc

While 1
   $msg = GUIGetMsg()

   If $msg = $swe Then
   _FileWriteToLine("test.txt", 1, GUICtrlRead($f3edit), 1)
   _FileWriteToLine("test.txt", 2, GUICtrlRead($f4edit), 1) 
   _FileWriteToLine("test.txt", 3, GUICtrlRead($f5edit), 1)
   _FileWriteToLine("test.txt", 4, GUICtrlRead($f6edit), 1)
 ExitLoop
   EndIf
   If $msg = $closeButton Then
 Exit
   EndIf
   If $msg = $GUI_EVENT_CLOSE Then
 Exit
   EndIf
WEnd GUIDelete()
Link to comment
Share on other sites

Also small inconvenience, I can't click on the control edit, I can only use tab to select and edit them.

.........

The only problem now is that I don't know how to make the 4 instances of control edit to be in focus when I click on them.

I'm using Windows XP and I have no trouble clicking the boxes and typing in them. I haven't heard of anyone having trouble with edits before. I don't know what to tell you. Have you tried them on a different system? Also, what OS and architecture are you using (32/64)?

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...