Autohotkey Write and Read Variables From File
I am working on a project where the user will demand to give unique X,Y coordinates for the script to run. At that place are 4 buttons, and when the push is pushed information technology and then waits until #due south is pushed and the ten,y will be saved to a txt file. When the user presses F1 it saves the x,y coordinates to a settings.txt file. The get-go issue I'm trying to figure out is if I have 4 different buttons, how tin I take information technology write a unqiue entry for each line. I want the first button (Subject button) to make an entry that says something like "Subject field X- Y-" so that later I can use a readline that says if Contains "Field of study", split on "-" so so I can use what is returned into my SubjectXVariable and SubjectYVariable. So the starting time upshot at hand, is how can I brand the FileAppend employ a unique entry?
Here is what I accept so far.
Credit goes to codekiller [url]http://www.autohotkey.com/customs/viewtopic.php?f=ane&t=93930[/url] CoordMode Mouse, Screen Gui Add, Button, vButton1 gGetCoord, Coordinate 1 Gui Add, Edit, ys vCoord1 readonly Gui Show Return GetCoord: CoordTmp := SubStr(A_GuiControl, 7) Return F1:: MouseGetPos 10, Y GuiControl , , Coord%CoordTmp%, %X%`, %Y% FileAppend, 10-%X% Y-%Y% `n, Settings.txt Render GuiEscape: GuiClose: ExitApp
Where the F1 is what triggers the writing to the file, I'thou not sure how I can utilise the single section of code to write unique entries. The just thing I can recall of is to have four seperate hotkeys that store the variable and its unique entry, which seems like a clutter.
F1:: MouseGetPos X, Y GuiControl , , Coord%CoordTmp%, %X%`, %Y% FileAppend, Subject: X-%10% Y-%Y% `due north, Settings.txt Render F2:: MouseGetPos Ten, Y GuiControl , , Coord%CoordTmp%, %10%`, %Y% FileAppend, Details: X-%X% Y-%Y% `northward, Settings.txt Return
Could I somehow utilize a button characterization to laissez passer a variable that will and so trigger an if-else statement in the hotkey?
Pseudo code If Subject is clicked, varChoice = i If Details is clicked, varChoice = ii F1:: if varChoice = one FileAppend, Subject: X-%X% Y-%Y% `north, Settings.txt else if varChoice = 2 FileAppend, Details: X-%X% Y-%Y% `n, Settings.txt
After I figure out how to take each push button/hotkey store its ten,y entry to the Settings.txt file I demand to figure out how to make it and then each new store replaces the previous line of text. FileAppend will add the new line at the lesser, what I want to exercise is have 4 lines of text that never grows, but but replaces each line based on what data is getting input.
So comes the whole reading from the file issue. Simply perahpps I'll focus on this for now and come up back to that later.
#1 - Posted 23 Oct 2012 - 10:47 PM
- Back to top
Alright, I believe IniWrite would be significantly more than useful than FileAppend. Lets say you run IniWrite, Value, Mylittle.ini,Section, Key
twice. The first fourth dimension information technology will create the file and write the value, because the Mylittle.ini didn't exist before, then overwrites that entry. IniWrite will never make duplicate Keys in the same section, it will always overwrite.
"Could I somehow use a push button label to pass a variable that will then trigger an if-else statement in the hotkey?"
Gui, Add, Push button, v%A_NowUTC% gButtonPressme,Press me Gui, Add, Push, v%A_Now% gButtonPressme,Press me2 Gui, Add together, Button, vHerpwhenyouderp gButtonPressme,Press me3 Gui, Testify Return GuiClose: Gui, Destroy Render ButtonPressMe: GuiControlGet, OutputVar, FocusV MsgBox %OutputVar% Return
You may need more info, merely that'due south all I could meet you conspicuously asking for. Also IniRead. A .ini file is just a particularly structured text file, open up it in notepad.
#ii - Posted 23 Oct 2012 - 11:13 PM
- Dorsum to top
:lol:
Thank you for the credit 8-)
Base on my previous script :
CoordMode Mouse, Screen Gui Add, Button, vButton1 gGetCoord, Coordinate 1 Gui Add together, Button, vButton2 gGetCoord, Coordinate 2 Gui Add, Button, vButton3 gGetCoord, Coordinate three Gui Add, Button, vButton4 gGetCoord, Coordinate 4 Gui Add together, Edit, ys vCoord1 readonly Gui Add, Edit, vCoord2 readonly Gui Add, Edit, vCoord3 readonly Gui Add, Edit, vCoord4 readonly Loop 4 { Button := "Button" A_Index IniRead 10, Coordinates.ini, X_Coord, Coord%A_Index%, %A_Space% IniRead Y, Coordinates.ini, X_Coord, Coord%A_Index%, %A_Space% If (X And Y) GuiControl , , Coord%A_Index%, %Ten%`, %Y% } Gui Show Return GetCoord: CoordTmp := SubStr(A_GuiControl, 7) ToolTip Waiting for F1... SetTimer TP, 1300 Return F1:: If (CoordTmp) { ToolTip MouseGetPos Ten, Y GuiControl , , Coord%CoordTmp%, %X%`, %Y% IniWrite %X%, Coordinates.ini, X_Coord, Coord%CoordTmp% IniWrite %Y%, Coordinates.ini, Y_Coord, Coord%CoordTmp% } Return GuiEscape: GuiClose: ExitApp TP: SetTimer TP, Off ToolTip Return
#3 - Posted 24 October 2012 - xi:59 AM
- Back to meridian
CodeKiller, Yous're unreal! That does exactly what I'm trying to accomplish. I'll accept to pick through the code to fully empathise what its doing, simply that works awesomely. Thank you over again for your input guys.
#iv - Posted 24 October 2012 - 03:35 PM
- Back to top
very helpful. I've been using the AutoIt3 Window Spy to notice coords, and so quickly alt-tabbing over the the script to type in coordinates I read from the AutoIt3 Window Spy. This elementary GUI is a much better tool for coordinate gathering.
#5 - Posted 07 November 2012 - 10:35 PM
- Back to top
Source: https://www.autohotkey.com/board/topic/86052-solved-how-to-store-then-read-variables-from-txt-file/
0 Response to "Autohotkey Write and Read Variables From File"
Post a Comment