How to incorporate .ini files? (Help please)
How to incorporate .ini files? (Help please)
Can someone help me with .ini files? I have no idea what i'm doing.
I want to include 3 files along with the AHK script that will allow the user to customize the hotkeys in "ra" "sh" "fe" etc. "1,2,3,4 etc." instead they can make it to something they would like other than 1,2,3,4 etc. for each image. Then the scan area customize-able and user changeable (static X1 := 0, Y1 := 0, X2 := A_ScreenWidth, Y2 := A_ScreenHeight), last but not least the hotkey for activation. In this case it's 1 "*1::SetTimer WatchSpells, 10" "*1 Up::SetTimer WatchSpells, Off"
If I could get pointed in the right direction I would greatly appreciate it as I have no clue how to work this!
#NoEnv
#SingleInstance Force
SendMode Input
SetBatchLines -1
CoordMode Pixel
*1::SetTimer WatchSpells, 10
*1 Up::SetTimer WatchSpells, Off
WatchSpells() {
static X1 := 0, Y1 := 0, X2 := A_ScreenWidth, Y2 := A_ScreenHeight
, SPELL_KEYMAP := {"ra": "1"
, "sh": "2"
, "fe": "3"
, "re": "4"
, "ri": "5"
, "th": "6"
, "ti": "7"}
for spell, key in SPELL_KEYMAP
{
ImageSearch, , , X1, Y1, X2, Y2, % "C:\Users\Abex\Documents\d.f\" spell ".png"
if !ErrorLevel
Send % key
}
}
I want to include 3 files along with the AHK script that will allow the user to customize the hotkeys in "ra" "sh" "fe" etc. "1,2,3,4 etc." instead they can make it to something they would like other than 1,2,3,4 etc. for each image. Then the scan area customize-able and user changeable (static X1 := 0, Y1 := 0, X2 := A_ScreenWidth, Y2 := A_ScreenHeight), last but not least the hotkey for activation. In this case it's 1 "*1::SetTimer WatchSpells, 10" "*1 Up::SetTimer WatchSpells, Off"
If I could get pointed in the right direction I would greatly appreciate it as I have no clue how to work this!
#NoEnv
#SingleInstance Force
SendMode Input
SetBatchLines -1
CoordMode Pixel
*1::SetTimer WatchSpells, 10
*1 Up::SetTimer WatchSpells, Off
WatchSpells() {
static X1 := 0, Y1 := 0, X2 := A_ScreenWidth, Y2 := A_ScreenHeight
, SPELL_KEYMAP := {"ra": "1"
, "sh": "2"
, "fe": "3"
, "re": "4"
, "ri": "5"
, "th": "6"
, "ti": "7"}
for spell, key in SPELL_KEYMAP
{
ImageSearch, , , X1, Y1, X2, Y2, % "C:\Users\Abex\Documents\d.f\" spell ".png"
if !ErrorLevel
Send % key
}
}
Re: How to incorporate .ini files? (Help please)
Please take a look at the help manual. There is a file command that allows to integrate a file into an executable.
If you do not want to compile your script you can use the script itself also as an ini file
If you do not want to compile your script you can use the script itself also as an ini file
ciao
toralf
toralf
Re: How to incorporate .ini files? (Help please)
First, create the INI files, like so:
Name that file SPELL_KEYMAP.ini (or change the filename in the following). Then, you could use the following to read all of the values at once:
That will create the SPELL_KEYMAP array for you.
Code: Select all
[SPELL_KEYMAP]
ra=1
sh=2
fe=3
re=4
ri=5
th=6
ti=7
Code: Select all
IniRead, SPELLS, SPELL_KEYMAP.ini, SPELL_KEYMAP ; Read all keys from the SPELL_KEYMAP section into a single string
SPELL_KEYMAP := [] ; Create the SPELL_KEYMAP array
Loop, Parse, SPELLS, "`n" ; Loop through the string one line at a time
{
Array := StrSplit(A_LoopField, "=") ; Store the current line's values before and after the = sign
SPELL_KEYMAP[Array[1]] := Array[2] ; Add the values to the SPELL_KEYMAP array
}
Re: How to incorporate .ini files? (Help please)
I shoud mention the following a one-liner string hack by Helgef:
Code: Select all
SetWorkingDir % A_ScriptDir
IniRead, SPELLS, SPELL_KEYMAP.ini, SPELL_KEYMAP
SPELL_KEYMAP := Object(StrSplit(SPELLS, ["=", "`n"])*)
MsgBox % SPELL_KEYMAP.re
Re: How to incorporate .ini files? (Help please)
[EDIT] The Hotkey command allows you to create hotkeys whose key names are not known until after the script has started running:A_AhkUser wrote: ↑06 May 2019, 19:40I shoud mention the following a one-liner string hack by Helgef:Code: Select all
SetWorkingDir % A_ScriptDir IniRead, SPELLS, SPELL_KEYMAP.ini, SPELL_KEYMAP SPELL_KEYMAP := Object(StrSplit(SPELLS, ["=", "`n"])*) MsgBox % SPELL_KEYMAP.re
Code: Select all
SetWorkingDir % A_ScriptDir
IniRead, SPELLS, SPELL_KEYMAP.ini, SPELL_KEYMAP ; read all keys from the SPELL_KEYMAP section into a single string.
SPELL_KEYMAP := Object(StrSplit(SPELLS, ["=", "`n"])*) ; get an associative array from the string by splitting it using '=' and '`n' (the linefeed character) as delimiters.
Hotkey % "*" . SPELL_KEYMAP.ra, enableTimer, On ; create a hotkey, using the relevant key's value of the associative array as the hotkey's activation key.
Hotkey % "*" . SPELL_KEYMAP.sh, disableTimer, On
return
enableTimer:
SetTimer WatchSpells, 10
return
disableTimer:
SetTimer WatchSpells, Off
return
WatchSpells() {
static _i := 0
ToolTip % ++_i
; your code...
}
Re: How to incorporate .ini files? (Help please)
That's quite nifty. I didn't realize that you could use Object that way. I'll have to remember that. It essentially replaces my 7 lines with only 2 lines. I love efficiency like that. Thanks for sharing.A_AhkUser wrote: ↑06 May 2019, 19:40I shoud mention the following a one-liner string hack by Helgef:Code: Select all
SetWorkingDir % A_ScriptDir IniRead, SPELLS, SPELL_KEYMAP.ini, SPELL_KEYMAP SPELL_KEYMAP := Object(StrSplit(SPELLS, ["=", "`n"])*) MsgBox % SPELL_KEYMAP.re
Re: How to incorporate .ini files? (Help please)
What line of code do I delete from my previous code in order to make this work?Osprey wrote: ↑06 May 2019, 18:55First, create the INI files, like so:
Name that file SPELL_KEYMAP.ini (or change the filename in the following). Then, you could use the following to read all of the values at once:Code: Select all
[SPELL_KEYMAP] ra=1 sh=2 fe=3 re=4 ri=5 th=6 ti=7
That will create the SPELL_KEYMAP array for you.Code: Select all
IniRead, SPELLS, SPELL_KEYMAP.ini, SPELL_KEYMAP ; Read all keys from the SPELL_KEYMAP section into a single string SPELL_KEYMAP := [] ; Create the SPELL_KEYMAP array Loop, Parse, SPELLS, "`n" ; Loop through the string one line at a time { Array := StrSplit(A_LoopField, "=") ; Store the current line's values before and after the = sign SPELL_KEYMAP[Array[1]] := Array[2] ; Add the values to the SPELL_KEYMAP array }
Do I delete the following below from the original script I posted?
{"ra": "1"
, "sh": "2"
, "fe": "3"
, "re": "4"
, "ri": "5"
, "th": "6"
, "ti": "7"}
I have made the ini file and put it in the same folder as the ahk script. I also added your code right below CoordMode Pixel
IniRead, SPELLS, SPELL_KEYMAP.ini, SPELL_KEYMAP ; Read all keys from the SPELL_KEYMAP section into a single string
SPELL_KEYMAP := [] ; Create the SPELL_KEYMAP array
Loop, Parse, SPELLS, "`n" ; Loop through the string one line at a time
{
Array := StrSplit(A_LoopField, "=") ; Store the current line's values before and after the = sign
SPELL_KEYMAP[Array[1]] := Array[2] ; Add the values to the SPELL_KEYMAP array
}
Kind of confused with this. Sorry
Re: How to incorporate .ini files? (Help please)
Yes, just remove your SPELL_KEYMAP := {stuff} assignment and put the code that I gave (or the simpler code that A_AhkUser gave) below it, like so:
Actually, it looks like you can probably simplify your code even further by combining the Loop and For loops, like so:
I would do that only if you don't have any other use for the SPELL_KEYMAP array elsewhere in your script (since we're not creating it in the interest of code efficiency). If you're not sure and want to play it safe, use the longer, first example, instead.
Code: Select all
#NoEnv
#SingleInstance Force
SendMode Input
SetBatchLines -1
CoordMode Pixel
*1::SetTimer WatchSpells, 10
*1 Up::SetTimer WatchSpells, Off
WatchSpells() {
static X1 := 0, Y1 := 0, X2 := A_ScreenWidth, Y2 := A_ScreenHeight
IniRead, SPELLS, SPELL_KEYMAP.ini, SPELL_KEYMAP ; Read all keys from the SPELL_KEYMAP section into a single string
SPELL_KEYMAP := [] ; Create the SPELL_KEYMAP array
Loop, Parse, SPELLS, "`n" ; Loop through the string one line at a time
{
Array := StrSplit(A_LoopField, "=") ; Store the current line's values before and after the = sign
SPELL_KEYMAP[Array[1]] := Array[2] ; Add the values to the SPELL_KEYMAP array
}
for spell, key in SPELL_KEYMAP
{
ImageSearch, , , X1, Y1, X2, Y2, % "C:\Users\Abex\Documents\d.f\" spell ".png"
if !ErrorLevel
Send % key
}
}
Code: Select all
#NoEnv
#SingleInstance Force
SendMode Input
SetBatchLines -1
CoordMode Pixel
*1::SetTimer WatchSpells, 10
*1 Up::SetTimer WatchSpells, Off
WatchSpells() {
static X1 := 0, Y1 := 0, X2 := A_ScreenWidth, Y2 := A_ScreenHeight
IniRead, SPELLS, SPELL_KEYMAP.ini, SPELL_KEYMAP ; Read all keys from the SPELL_KEYMAP section into a single string
Loop, Parse, SPELLS, "`n" ; Loop through the string one line at a time
{
Array := StrSplit(A_LoopField, "=") ; Store the current line's values before and after the = sign
ImageSearch, , , X1, Y1, X2, Y2, % "C:\Users\Abex\Documents\d.f\" Array[1] ".png"
if !ErrorLevel
Send % Array[2]
}
}
Re: How to incorporate .ini files? (Help please)
This has helped me so much, I went with the first code you sent as I wasn't sure and played it safe. I'm seeing that I can't add a = sign after the = for the script to recognize the hotkey for it. Is there a work around for that or do I just have to use another key? I tried {=} but that didn't work.Osprey wrote: ↑09 May 2019, 18:05Yes, just remove your SPELL_KEYMAP := {stuff} assignment and put the code that I gave (or the simpler code that A_AhkUser gave) below it, like so:
Actually, it looks like you can probably simplify your code even further by combining the Loop and For loops, like so:Code: Select all
#NoEnv #SingleInstance Force SendMode Input SetBatchLines -1 CoordMode Pixel *1::SetTimer WatchSpells, 10 *1 Up::SetTimer WatchSpells, Off WatchSpells() { static X1 := 0, Y1 := 0, X2 := A_ScreenWidth, Y2 := A_ScreenHeight IniRead, SPELLS, SPELL_KEYMAP.ini, SPELL_KEYMAP ; Read all keys from the SPELL_KEYMAP section into a single string SPELL_KEYMAP := [] ; Create the SPELL_KEYMAP array Loop, Parse, SPELLS, "`n" ; Loop through the string one line at a time { Array := StrSplit(A_LoopField, "=") ; Store the current line's values before and after the = sign SPELL_KEYMAP[Array[1]] := Array[2] ; Add the values to the SPELL_KEYMAP array } for spell, key in SPELL_KEYMAP { ImageSearch, , , X1, Y1, X2, Y2, % "C:\Users\Abex\Documents\d.f\" spell ".png" if !ErrorLevel Send % key } }
I would do that only if you don't have any other use for the SPELL_KEYMAP array elsewhere in your script (since we're not creating it in the interest of code efficiency). If you're not sure and want to play it safe, use the longer, first example, instead.Code: Select all
#NoEnv #SingleInstance Force SendMode Input SetBatchLines -1 CoordMode Pixel *1::SetTimer WatchSpells, 10 *1 Up::SetTimer WatchSpells, Off WatchSpells() { static X1 := 0, Y1 := 0, X2 := A_ScreenWidth, Y2 := A_ScreenHeight IniRead, SPELLS, SPELL_KEYMAP.ini, SPELL_KEYMAP ; Read all keys from the SPELL_KEYMAP section into a single string Loop, Parse, SPELLS, "`n" ; Loop through the string one line at a time { Array := StrSplit(A_LoopField, "=") ; Store the current line's values before and after the = sign ImageSearch, , , X1, Y1, X2, Y2, % "C:\Users\Abex\Documents\d.f\" Array[1] ".png" if !ErrorLevel Send % Array[2] } }
Also can I apply this sort of code in order to have a custom screen area instead of fixed at A_screenwidth A_screenheight? Maybe an .ini file for the static search as well? If you could show me that code I would be even more appreciative than I am right now
Seriously thank you for the time you have put in to help me!
Re: How to incorporate .ini files? (Help please)
If you mean that you're trying to do something like ra== in your INI file and it's not working, try replacing the Array := StrSplit(A_LoopField, "=") line with Array := StrSplit(A_LoopField, "=", , 2).
Yes, you can make the display area customizable according to values in an INI file. You can just add a section to your SPELL_KEYMAP.INI, like:
...and then add a few IniRead lines...
...in place of your X1, Y1, X2 and Y2 assignments. You could do a loop like before, but maybe it's best to show you how to do it like this, so that it's less confusing and you can better adapt it, yourself.
Yes, you can make the display area customizable according to values in an INI file. You can just add a section to your SPELL_KEYMAP.INI, like:
Code: Select all
[General]
X1=0
Y1=0
X2=-1 ; -1 means use the screen width
Y2=-1 ; -1 means use the screen height
Code: Select all
IniRead, X1, SPELL_KEYMAP.ini, General, X1
IniRead, Y1, SPELL_KEYMAP.ini, General, Y1
IniRead, X2, SPELL_KEYMAP.ini, General, X2
IniRead, Y2, SPELL_KEYMAP.ini, General, Y2
If(X2 = -1)
X2 := A_ScreenWidth
If(Y2 = -1)
Y2 := A_ScreenHeight
Re: How to incorporate .ini files? (Help please)
That worked for the hotkeys having ra==, now they work perfectly!
Where do I put this code in the above code and what do I delete? Sorry im confused again just like the last time. Do I delete static X1 := 0, Y1 := 0, X2 := A_ScreenWidth, Y2 := A_ScreenHeight and replace it with the the code below?
Also, is this the correct format for the ini file for both the x1y1x2y2 custom area AND the custom hotkeys for the spells?
I really appreciate all the help
Code: Select all
#NoEnv
#SingleInstance Force
SendMode Input
SetBatchLines -1
CoordMode Pixel
*1::SetTimer WatchSpells, 10
*1 Up::SetTimer WatchSpells, Off
WatchSpells() {
static X1 := 0, Y1 := 0, X2 := A_ScreenWidth, Y2 := A_ScreenHeight
IniRead, SPELLS, SPELL_KEYMAP.ini, SPELL_KEYMAP ; Read all keys from the SPELL_KEYMAP section into a single string
SPELL_KEYMAP := [] ; Create the SPELL_KEYMAP array
Loop, Parse, SPELLS, "`n" ; Loop through the string one line at a time
{
Array := StrSplit(A_LoopField, "=") ; Store the current line's values before and after the = sign
SPELL_KEYMAP[Array[1]] := Array[2] ; Add the values to the SPELL_KEYMAP array
}
for spell, key in SPELL_KEYMAP
{
ImageSearch, , , X1, Y1, X2, Y2, % "C:\Users\Abex\Documents\d.f\" spell ".png"
if !ErrorLevel
Send % key
}
}
Code: Select all
IniRead, X1, SPELL_KEYMAP.ini, General, X1
IniRead, Y1, SPELL_KEYMAP.ini, General, Y1
IniRead, X2, SPELL_KEYMAP.ini, General, X2
IniRead, Y2, SPELL_KEYMAP.ini, General, Y2
If(X2 = -1)
X2 := A_ScreenWidth
If(Y2 = -1)
Y2 := A_ScreenHeight
Code: Select all
[SPELL_KEYMAP]
ra=8
sh=+{F2}
fe=-
re=6
ri=7
th=8
ti=9
fl=+{F2}
[General]
X1=0
Y1=0
X2=-1 ; -1 means use the screen width
Y2=-1 ; -1 means use the screen height
Re: How to incorporate .ini files? (Help please)
Also do you have a PP anywhere? I'd love to give you some $$ for the helpOsprey wrote: ↑10 May 2019, 19:57If you mean that you're trying to do something like ra== in your INI file and it's not working, try replacing the Array := StrSplit(A_LoopField, "=") line with Array := StrSplit(A_LoopField, "=", , 2).
Yes, you can make the display area customizable according to values in an INI file. You can just add a section to your SPELL_KEYMAP.INI, like:
...and then add a few IniRead lines...Code: Select all
[General] X1=0 Y1=0 X2=-1 ; -1 means use the screen width Y2=-1 ; -1 means use the screen height
...in place of your X1, Y1, X2 and Y2 assignments. You could do a loop like before, but maybe it's best to show you how to do it like this, so that it's less confusing and you can better adapt it, yourself.Code: Select all
IniRead, X1, SPELL_KEYMAP.ini, General, X1 IniRead, Y1, SPELL_KEYMAP.ini, General, Y1 IniRead, X2, SPELL_KEYMAP.ini, General, X2 IniRead, Y2, SPELL_KEYMAP.ini, General, Y2 If(X2 = -1) X2 := A_ScreenWidth If(Y2 = -1) Y2 := A_ScreenHeight
Re: How to incorporate .ini files? (Help please)
Yes, put it in place of your X1, Y1, X2 and Y2 assignments. Your INI file looks correct, as well.
Thanks, but my help is free.
Thanks, but my help is free.
Re: How to incorporate .ini files? (Help please)
Code: Select all
#NoEnv
#SingleInstance Force
SendMode Input
SetBatchLines -1
CoordMode Pixel
*1::SetTimer WatchSpells, 10
*1 Up::SetTimer WatchSpells, Off
WatchSpells() {
IniRead, X1, SPELL_KEYMAP.ini, General, X1
IniRead, Y1, SPELL_KEYMAP.ini, General, Y1
IniRead, X2, SPELL_KEYMAP.ini, General, X2
IniRead, Y2, SPELL_KEYMAP.ini, General, Y2
If(X2 = -1)
X2 := A_ScreenWidth
If(Y2 = -1)
Y2 := A_ScreenHeight
IniRead, SPELLS, SPELL_KEYMAP.ini, SPELL_KEYMAP ; Read all keys from the SPELL_KEYMAP section into a single string
SPELL_KEYMAP := [] ; Create the SPELL_KEYMAP array
Loop, Parse, SPELLS, "`n" ; Loop through the string one line at a time
{
Array := StrSplit(A_LoopField, "=") ; Store the current line's values before and after the = sign
SPELL_KEYMAP[Array[1]] := Array[2] ; Add the values to the SPELL_KEYMAP array
}
for spell, key in SPELL_KEYMAP
{
ImageSearch, , , X1, Y1, X2, Y2, % "C:\Users\Abex\Documents\d.f\" spell ".png"
if !ErrorLevel
Send % key
}
}
Code: Select all
static X1 := 0, Y1 := 0, X2 := A_ScreenWidth, Y2 := A_ScreenHeight
Re: How to incorporate .ini files? (Help please)
Code: Select all
#NoEnv
#SingleInstance Force
SendMode Input
SetBatchLines -1
CoordMode, Pixel, Screen
INI_FILE := A_ScriptDir "\mySettings.ini"
if not (FileExist(INI_FILE))
FileAppend,
(LTrim Join`n
[area]
x1=0
y1=0
x2=-1
y2=-1
[keymap]
ra=1
sh=2
fe=3
re=4
ri=5
th=6
ti=7
[hotkey]
keyName=1
), % INI_FILE, UTF-16
IniRead, hotkey, % INI_FILE, hotkey, keyName
Hotkey % "*" . hotkey, setTimer, On
IniRead, coordinates, % INI_FILE, area
data := StrSplit(coordinates, ["=", "`n"])
i := 0
Loop % data.count()/2 {
k := data[ ++i ], v := data[ ++i ]
if (v = -1) {
substr := SubStr(k, 1, 1)
SysGet, v, % Ord(substr) - Ord("x")
area%k% := v
} else area%k% := v
}
oKeymap := []
IniRead, keymap, % INI_FILE, keymap
Loop, Parse, keymap, "`n"
ObjRawSet(oKeymap, StrSplit(A_LoopField, "=")*)
return
setTimer:
SetTimer, watchSpells, 10
KeyWait % hotkey
SetTimer, watchSpells, Off
return
watchSpells:
for spell, key in oKeymap
{
ImageSearch,,, % areax1, % areay1, % areax2, % areay2, % "C:\Users\Abex\Documents\d.f\" spell ".png"
if (!ErrorLevel)
send % key
}
return
@admin It took me ten minutes to post the code.... I could not posted it without being blocked until I used the temp variable substr instead of SubStr(k, 1, 1) @ SysGet, v, % Ord(substr) - Ord("x")...
Re: How to incorporate .ini files? (Help please)
Thanks for the help but Im wondering how to implement the ini read code that the above was sent to me, would you by any chance be able to help me place that ini read code in ?A_AhkUser wrote: ↑14 May 2019, 00:46not tested. Hope this helps.Code: Select all
#NoEnv #SingleInstance Force SendMode Input SetBatchLines -1 CoordMode, Pixel, Screen INI_FILE := A_ScriptDir "\mySettings.ini" if not (FileExist(INI_FILE)) FileAppend, (LTrim Join`n [area] x1=0 y1=0 x2=-1 y2=-1 [keymap] ra=1 sh=2 fe=3 re=4 ri=5 th=6 ti=7 [hotkey] keyName=1 ), % INI_FILE, UTF-16 IniRead, hotkey, % INI_FILE, hotkey, keyName Hotkey % "*" . hotkey, setTimer, On IniRead, coordinates, % INI_FILE, area data := StrSplit(coordinates, ["=", "`n"]) i := 0 Loop % data.count()/2 { k := data[ ++i ], v := data[ ++i ] if (v = -1) { substr := SubStr(k, 1, 1) SysGet, v, % Ord(substr) - Ord("x") area%k% := v } else area%k% := v } oKeymap := [] IniRead, keymap, % INI_FILE, keymap Loop, Parse, keymap, "`n" ObjRawSet(oKeymap, StrSplit(A_LoopField, "=")*) return setTimer: SetTimer, watchSpells, 10 KeyWait % hotkey SetTimer, watchSpells, Off return watchSpells: for spell, key in oKeymap { ImageSearch,,, % areax1, % areay1, % areax2, % areay2, % "C:\Users\Abex\Documents\d.f\" spell ".png" if (!ErrorLevel) send % key } return
@admin It took me ten minutes to post the code.... I could not posted it without being blocked until I used the temp variable substr instead of SubStr(k, 1, 1) @ SysGet, v, % Ord(substr) - Ord("x")...
Re: How to incorporate .ini files? (Help please)
Have you run it? It should do all the stuff. After running it, you will in all likelihood find an ini file called mySettings.ini, in the script's own directory.
@Osprey You're welcolme I'm glad you like it. Although it appeared no to be a solution here (= possibly used as value). You might also be intersted in string hacks. Cheers
Re: How to incorporate .ini files? (Help please)
I'm trying to have no values in the script and let the user set their own from the ini file. @Osprey gave me the code I was looking for to implement into my script. It is very clean and was wondering how to use it in my ownA_AhkUser wrote: ↑14 May 2019, 15:33Have you run it? It should do all the stuff. After running it, you will in all likelihood find an ini file called mySettings.ini, in the script's own directory.
@Osprey You're welcolme I'm glad you like it. Although it appeared no to be a solution here (= possibly used as value). You might also be intersted in string hacks. Cheers
This code below
Code: Select all
IniRead, X1, SPELL_KEYMAP.ini, General, X1
IniRead, Y1, SPELL_KEYMAP.ini, General, Y1
IniRead, X2, SPELL_KEYMAP.ini, General, X2
IniRead, Y2, SPELL_KEYMAP.ini, General, Y2
If(X2 = -1)
X2 := A_ScreenWidth
If(Y2 = -1)
Y2 := A_ScreenHeight
Code: Select all
#NoEnv
#SingleInstance Force
SendMode Input
SetBatchLines -1
CoordMode Pixel
*1::SetTimer WatchSpells, 10
*1 Up::SetTimer WatchSpells, Off
WatchSpells() {
static X1 := 0, Y1 := 0, X2 := A_ScreenWidth, Y2 := A_ScreenHeight
IniRead, SPELLS, SPELL_KEYMAP.ini, SPELL_KEYMAP ; Read all keys from the SPELL_KEYMAP section into a single string
SPELL_KEYMAP := [] ; Create the SPELL_KEYMAP array
Loop, Parse, SPELLS, "`n" ; Loop through the string one line at a time
{
Array := StrSplit(A_LoopField, "=") ; Store the current line's values before and after the = sign
SPELL_KEYMAP[Array[1]] := Array[2] ; Add the values to the SPELL_KEYMAP array
}
for spell, key in SPELL_KEYMAP
{
ImageSearch, , , X1, Y1, X2, Y2, % "C:\Users\Abex\Documents\d.f\" spell ".png"
if !ErrorLevel
Send % key
}
}
Re: How to incorporate .ini files? (Help please)
Code: Select all
IniRead, SPELLS, SPELL_KEYMAP.ini, SPELL_KEYMAP ; Read all keys from the SPELL_KEYMAP section into a single string
SPELL_KEYMAP := [] ; Create the SPELL_KEYMAP array
Loop, Parse, SPELLS, "`n" ; Loop through the string one line at a time
{
Array := StrSplit(A_LoopField, "=") ; Store the current line's values before and after the = sign
SPELL_KEYMAP[Array[1]] := Array[2] ; Add the values to the SPELL_KEYMAP array
}
IniRead, X1, SPELL_KEYMAP.ini, General, X1
IniRead, Y1, SPELL_KEYMAP.ini, General, Y1
IniRead, X2, SPELL_KEYMAP.ini, General, X2
IniRead, Y2, SPELL_KEYMAP.ini, General, Y2
If(X2 = -1)
X2 := A_ScreenWidth
If(Y2 = -1)
Y2 := A_ScreenHeight
*1::SetTimer WatchSpells, 10
*1 Up::SetTimer WatchSpells, Off
return
WatchSpells:
for spell, key in SPELL_KEYMAP
{
ImageSearch, , , X1, Y1, X2, Y2, % "C:\Users\Abex\Documents\d.f\" spell ".png"
if !ErrorLevel
Send % key
}
return
Who is online
Users browsing this forum: AlFlo and 215 guests